Thursday, December 31, 2009

[jQuery] Re: Referring to the current DOM object in a jQuery method parameter list

This should do the job:

$("#someid").each(function() { $(this).text($(this).attr("alt")); });

It is longer and more unreadable than your original code

$("#someId").text($("#someId").attr("alt"));

but you do get rid of redundancy = you do not have to write the same
selector twice, which is generally bad in programming... for a simple
selector like #someid, you may write it your way, but for a complex
selector, writing it twice is a bad idea..

No comments: