tags:

views:

300

answers:

3

hi all,

I want to count the Href in a page using Jquery .

Just for refrence: i have random number of hyperlinks in a page for each user and all hrefs are diffrentiated with thier id eg. user_1,user_2,.... so here im unable to call the function on onclick event using Jquery since each href is has different name and cannot also write separate jquery functions which varies for each user . so if i could get to count hrefs in a page i could easily call the function

waiting for reply

Thanks Mukesh

+5  A: 

Since the elements A, AREA, BASE and LINK can have a href attribute:

$('a[href], area[href], base[href], link[href]').size()

That will return the number of elements with a href attribute. The more specific the question, the more specific the answers.

Gumbo
...or you can use `$('[href]').size()` to match everything with a href-attribute.
nikc
+1  A: 

i am not a js/jquery expert .. but should u be able to get back an array of "a" tags with

$("a") ?

Sabeen Malik
It would be worth qualifying the selector with `a[href]` to differentiate between hyperlinks and named anchors.
Alex Barrett
yes that makes sense .. thanks for elaborating that.
Sabeen Malik
@Alex: that is true, but you shouldn't be using the `<a>` tag for names anchors, you should use the `id` attribute.
DisgruntledGoat
+3  A: 

$('[href]').length ? (84 in this page right now, 88 when my comment wil be on it ? :p)

vvo