dimanche 1 mars 2015

$(this).attr({class: "activeTab"}); is not working because this is undefined

This is my JS code, the problem I have is the one in the title. It seems as though $(this) is returning undefined.:



function load() {
$(".inactiveTab").attr("onclick", "clickInactiveTab()");
}

function clickInactiveTab() {
$(this).attr("class", "activeTab");
}


The html is the following:



<div class="inactiveTab">Tab 1</div>
<div class="inactiveTab">Tab 2</div>




Aucun commentaire:

Enregistrer un commentaire