ectype
ectype

Reputation: 15085

How to find the rel attribute jQuery

I have a bunch of elements that contain the rel attribute.

I'm trying to use this to loop through the elements to get the value of each.

$('area').find('rel').each(function(index){
    alert(index);
});

However it doesn't seem to work.

Upvotes: 0

Views: 4490

Answers (3)

ectype
ectype

Reputation: 15085

Nevermind figured it out.

$('area[rel]').each(function(index){
    alert(index);
});

Upvotes: 0

Jacob
Jacob

Reputation: 1536

The argument to find is supposed to be a selector. To actually pull out the element values, you want something like:

$('[rel]').each(function() {
    alert($(this).attr('rel'));
});

Upvotes: 3

Mikulas Dite
Mikulas Dite

Reputation: 7941

$('[rel]') would find all nodes with the rel attribute in document.

$('div').find('[rel]') would find all nodes with the rel attribute in under any div.

Upvotes: 2

Related Questions