私はアンカータグでデータ属性を使用していますが、次のイベントが発生すると、その属性を持つすべてのリンクが変更されると思います。ID を使用したくありません。イベントをクリックされたリンクにのみバインドしたいだけです...非常に簡単なはずですが、これを解決できません。これは、Twitter Bootstrap の折りたたみと組み合わせて、続きを読む / 続きを読むの抜粋機能として使用されています。
//Excerpt functions
$('.collapse').on('shown', function () {
$('[data-target]').click(function() {
$(this).html('» More');
});
});
$('.collapse').on('hidden', function () {
$('[data-target]').click(function() {
$(this).html('« Less');
});
});
私のhtmlは次のようになります
<a href="#" data-toggle="collapse" data-target="#more1">» More</a>
<div id="more1" class="collapse"></div>