If you ever wanted to loop through all the hyperlink elements in a page, jQuery provides .each() function which will provide you the desired result.
e.g
$("a").each(function(){
//access the element here.
});
This can also be done in a more cleaner way as displayed below.
$("a").attr("href", function(i, hRef) {
//access the element here.
});
I prefer the second option as will not create additional object when iterating elements.
Cheers,
Samitha
e.g
$("a").each(function(){
//access the element here.
});
This can also be done in a more cleaner way as displayed below.
$("a").attr("href", function(i, hRef) {
//access the element here.
});
I prefer the second option as will not create additional object when iterating elements.
Cheers,
Samitha
No comments:
Post a Comment