Raviv g
Raviv g

Reputation: 65

jQuery get value of each A tag without refresh the page

i need you'r help..to get each A tag href value .

E.G:

<a id="#founditems" href="45S4#6#@5463&">press on me</a>
<a id="#founditems" href="ssdf#%dfd@@Df">press on me</a>
<a id="#founditems" href="ghfAS3#SDF%^f">press on me</a>
<a id="#founditems" href="DFGDF#%^SDFFG">press on me</a>

I want to get each value of A tag when i press on each of one of them. This list coming from AJAX with PHP with foreach , now in my client side when i press on "press on me" i want to take his value and to do somthing with it .

So far i did :

$(document).on('click','#founditems',function(e){
            $('#founditems').each(function() {  
                alert($(this).attr('href'));

        });

  });

The alert keep give only the first A href value.

I am newbie at javascript/jquery anyone can help me ?

PS: If you got any better way to take this value , it will be nice to get advice..i prefer take this value with php, but i using AJAX to take this value from php file with foreach, so the page not refreshed.

Thanks.

Upvotes: 0

Views: 451

Answers (3)

Udit Bhardwaj
Udit Bhardwaj

Reputation: 1781

in case you want only clicked item's href

$(document).on('click','#founditems',function(e){
        var $this=$(this)

        alert($this.attr('href'));
});

Upvotes: 0

user3012567
user3012567

Reputation: 33

Instead of #ID(founditems) change it to class attribute and you can loop it like following,

$('.founditems').each(function() {
   alert($(this).attr('href'));
});

all the best.

Upvotes: 1

Tom Chung
Tom Chung

Reputation: 1422

id is a unique value. you should select all a element by:

$('a')

Upvotes: 0

Related Questions