私は次のものを持っています:
だから今私はul.children
このように切り替えています:
$('a.expand-cat-item').on('click', function() {
$(this).closest('li.cat-item').find('ul.children').toggle('slow');
});
ここで、+記号を内部の-記号に変更しますa.expand-cat-item
(これはトグルとしても機能します)。
それを達成する方法は?
私は次のものを持っています:
だから今私はul.children
このように切り替えています:
$('a.expand-cat-item').on('click', function() {
$(this).closest('li.cat-item').find('ul.children').toggle('slow');
});
ここで、+記号を内部の-記号に変更しますa.expand-cat-item
(これはトグルとしても機能します)。
それを達成する方法は?
条件演算子を使用? :
して、テキスト切り替え条件を作成できます。
$('a.expand-cat-item').on('click', function() {
$(this).closest('li.cat-item').find('ul.children').toggle('slow');
$(this).text($(this).text() == "+" ? "-" : "+");
});
試す
$('a.expand-cat-item').on('click', function() {
$(this).closest('li.cat-item').find('ul.children').toggle('slow');
if ($(this).text() == '+ '){
$(this).text('- ');
}
else{
$(this).text('+ ');
}
});
これを使って:
$('a.expand-cat-item').text("- ");
$('a.expand-cat-item').on('click', function() {
var $this = $(this);
$this.closest('li.cat-item').find('ul.children').toggle('slow');
var html = '+';
if($this.html().indexOf('+') > -1){
html = '-';
}
$this.html(html);
});