0

Here is my structure :

<ul class="subcategories" id="items-23">
    <li>
        <a data-item="35" class="itemLink">
            others
        </a>
    </li>
    <li>
        <a data-item="24" class="itemLink">
            Cars
        </a>
    </li>
    <li>
        <a data-item="28" class="item-link activeSelection">
            Bikes
        </a>
    </li>
</ul>

I want to add this button to the activeSelection only : <a class="btn item-next" id="NextButton" href="#">Next</a>. When i click on <li> it add activeSelection class.

I tried in the source code. As <li> are generated automatically, if i had the button, when see it on every <li>.

Someone understand my problem and could have a solution for it ?

Thanks in advance !!!

------------the result expected -----------

As you see i've selected the first categorie, and my button is displayed

http://rentaweb.fr/wp-content/uploads/2013/07/screenshot.png

4

1 に答える 1

1

特定のクラスでその要素に何かを追加するには:

$('<input type="button" value="Hello"/>').appendTo('.activeSelection');

クリック イベントを登録するには:

$('.subcategories').on('click', '.itemLink', function(){
    $('.activeSelection').removeClass('activeSelection'); // Remove the current as suggested
    $(this).addClass('activeSelection');
});

on() の使用法に注意してください.itemLink。これは、イベントフックを再適用する必要なく、新しい要素を動的に処理できるようにするためです。

于 2013-07-30T17:00:53.110 に答える