Reputation: 460
hey there i am trying to create a new html attribute for which i am following this link, in which i have succeeded. i am also trying to echo the value of the attribute in a number of the same html tags, which in this case is an <a>
tag, which is inside a div tag and am using the jquery
.find()
to get the value of those attributes in those <a>
tags. but i only get one attribute value, which is the first one, but not the rest, basically i want to echo the value of the attribute in all the <a>
tags. how can i do this, oh and a working fiddle
Upvotes: 0
Views: 65
Reputation: 25527
USe .each()
to loop through each node
$("#gh").click(function() {
$("#new_attr").find('.showItLink').each(function(){
alert($(this).attr("textToShow"));
});
});
If you want to get the exact node which contains a specific attribute value, use like this
$('.showItLink[textToShow="This is the text to show0"]')
Upvotes: 1
Reputation: 15393
you acheive the scenario through .each()
in jquery
$("#gh").click(function() {
$("#new_attr").find('.showItLink').each(function() {
if($(this).attr("textToShow") == "This is the text to show5") {
alert ('found');
}else{
alert ('not found');
}
});
});
Upvotes: 0