我想添加一個類到元素數組的特定元素,但是我想基於for循環的變量添加它,而不僅僅是一個隨機數,並將其添加到多個元素(如果必須的話),但重點是,我需要使用給定的變量搜索元素!jQuery選擇變量作爲選擇器的元素類的特定元素
for(var a = 0; a < array.length; a++){
$('.results').append('some html divs here');
if(array[a].id == $.cookie('userId')){
$('.buyButton').addClass('disabled'); // here's my problem I don't want to add the
//disabled class to every element with the buyButton class, but just the one selected by the if statement
}
}
謝謝!
你能澄清正是你」再問一次?期望的行爲是什麼,目前發生了什麼? – Utkanos
@Utkanos禁用功能被添加到每個.buyButton元素。我希望它被添加到只有那些數組[a] .id等於cookie(因此「if」語句!) –