2017-02-09 11 views
1

私はコードの下に持って取得タグ

  $('li').click(function(e){ 
     e.preventDefault(); 
     $(this).addClass("active1"); 

    // $(this a).addClass("acolor"); // I am trying this 

});; 

アンカータグは、Liタグ内にあるとLiのクリック時に私は、テキストの色変更したい - .acolorクラスにCSSであり

ここで私は李を得ています。タグを取得したいと思います。

ご協力いただければ幸いです!ありがとう

+0

Iは(http://stackoverflow.com/search?q=%5Bjquery%5D+find+element+inside+this)[ '[jqueryの] this'内部要素を見つける]を検索することによって、重複を発見、それは私にhttp://stackoverflow.com/questions/10604251/call-elements-inside-thisにさせてくれました。 –

答えて

1

find()メソッドを使用します。

$(this).find('a').addClass("acolor"); 

またはjQueryの方法でcontextとしてthisを提供します。

$('a', this).addClass("acolor"); 
+0

ありがとうPranav !!それは私のために働いた:) – CodeWithCoffee

+0

これをアクティブとして追加した後、私は別の李をクリックし、現在の李から削除したらどのように削除することができますか? – CodeWithCoffee

+0

@CodeWithCoffee '$(this).sibling()。find( 'a')。removeClass(" acolor ");' –

関連する問題