Click here to Skip to main content
15,884,047 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a td tag and this have more than one a tag with href.i want to get href of a tag using jquery using loop how can i find it. please help thanks in advance

my code is

XML
<td colspan="4">
<a id="currentpage">1</a>
<a href="home/Search?txtSearch=a&Page="2">2</a>
<a  href="home/Search?txtSearch=a&Page="3">3</a>
<a  href="home/Search?txtSearch=a&Page="4">4</a>
</td>



jquery code:

C#
var r = $('.webgrid-table tfoot tr td a');
               for (var i = 0; i < r.length; i++) {
                   alert("Hello "+r.attr('href'));
               }
Posted
Updated 16-Sep-14 0:35am
v2
Comments
hypermellow 16-Sep-14 6:25am    
Can you post you code, and what you have tried?

1 solution

First, you should not have multiple attributes with the same name. It kind of does not make sense. How would you differentiate between them?

Second, to read an attribute of an element you can use .attr() in jQuery. Look here for documentation:

http://api.jquery.com/attr/[^]
 
Share this answer
 
Comments
Thanks7872 16-Sep-14 6:55am    
+5...!

Nice to see you after a long time :-)
Manas Bhardwaj 16-Sep-14 6:59am    
thx!

Yes, old addictions don't go easily ;)
Thanks7872 16-Sep-14 7:07am    
:laugh: :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900