javascript - How can i know which class was selected via jQuery & JS -


i have list links:

<li class="link-1"><a href="#">one</a></li> <li class="link-2"><a href="#">two</a></li> <li class="link-3"><a href="#">three</a></li> .. 

user clicks on link, jquery want display content of link.. somthing like:

$(".link-??? a").click(function() {     alert($(".link-??? a").html()); }) 

something this. not going create x function (as number of links), can do? should replace ??? in somtehing else..

you could do:

 $('li[class^="link"] a').click(... 

however work if li have 1 class or if link-x class first in list.

inside handler can use $(this) refer a element:

alert($(this).text()); 

much better give li elements common class:

<li class="link"><a href="#">one</a></li> <li class="link"><a href="#">two</a></li> <li class="link"><a href="#">three</a></li> 

$('.link a').click(... more reliable.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -