2017-06-24 17 views
2

ここに脳のおならがある。JQueryでこれを変数と組み合わせる方法

$(function() { 

    $('#featured-top .option').click(function(){ 

     $('#featured-top .option a').html('Close'); 

     $('#featured-top .featured-content').slideToggle(); 

    }); 

}); 

このラインここ:

$(this).html('Close'); 

しかし、どのように私はセレクタを使用してリンクにアクセスします:これを使用しようとして

$('#featured-top .option a').html('Close'); 

イム私はこのコードを持っていますか?私は試しました:

$(this + 'a').html('Close'); 

しかし、それは動作しません。その単純な、私は知っているが、何らかの理由で私はそれをすべて突然理解することができない。

+0

おそらく '$(this).find( 'a');'または '$(this).closest( 'a')'を使用する必要があります。 –

答えて

1

あなたはそうしていません。

$('#featured-top .option').click(function(){ 
    // Use this way: 
    $(this).find('a').html('Close'); 
    // If you wanna change this as well, you can use: 
    $(this).closest("#featured-top").find('.featured-content').slideToggle(); 
}); 
関連する問題