asdf
asdf

Reputation: 460

get the value of a newly created html attribute

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

Answers (2)

Anoop Joshi P
Anoop Joshi P

Reputation: 25527

USe .each() to loop through each node

$("#gh").click(function() {
    $("#new_attr").find('.showItLink').each(function(){
      alert($(this).attr("textToShow"));
    });
});

Fiddle

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"]')

Fiddle 2

Upvotes: 1

Sudharsan S
Sudharsan S

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');
    }


    });

});

DEMO

Upvotes: 0

Related Questions