2013-02-19 56 views
2

am stuck with a issue.juz started studying jquery recently..i do hav a issue如何只是一个<a tag> using jquery

i have a segment like this in ma html code..what i need is to select the li tag that comes just before the 'a' tag that i clicked.it would b helpful if someone helped me with this. i need to add a class named open in the li class just before the 'a' tag that is being clicked.. how can i do this using jquery..

<ul> 
<li class=''> 
     <a class ='value1'></a> 
      <div>some contents</div> 
</li> 

<li class=''> 
     <a class ='value 2'></a> 
      <div>some contents</div> 
</li> 

</ul> 

回答

1

Try:

$("a").click(function() { 
    $(this).parent().addClass("open"); 
}); 

http://jsfiddle.net/4hGvS/

我增加了一些内容,你a标记为这的jsfiddle工作之前得到李。

+0

谢谢你..我会检查一下.. :) – arteta 2013-02-19 14:57:51

相关问题