2017-02-15 76 views
0

我很難嘗試使用jQuery更改類的屬性。 「count ++」之前的行對.collapseA沒有任何影響,但上面的行確實有效。在jQuery中更改aria-controls屬性

$(document).ready(function(){ 
var count = 1; 
    $('.collapseTag').each(function (index, value) { 
     var newID = "collapse" + count; 
     $(this).attr("id", newID); 
     $(this).closest('.collapseA').attr("href" , "#" + newID); 
     $(this).closest('.collapseA').attr("aria-controls" , newID); 
     count++; 
    }); 
}); 

它的定位是:

<a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="" class="collapseA"> 

感謝

+1

應該工作.... –

+1

似乎工作。 https://jsfiddle.net/d5r2utdL/ –

+0

我會更新代碼,但我不認爲有什麼可以打破它 – ERushforth

回答

0

原來我只是需要,因爲對象指的是本身就已經刪除「最近」位。 DERP。

$(this).attr("aria-controls" , newID);