javascript - cant get data From data-n in element -
i have span
:
<span class="span-link" id="2" data-state="true" onclick="javascript: changestate(this.id);">change state</span>
and in javascript function use code value :
function changestate(_thingid) { alert(_thingid); var tt = $(this).attr("data-state"); alert(tt); }
i getting undefinded
data-state
. test $(this).data("state")
, getting undefined
.
whats problems?
you referencing id, not object, change this:
var tt = $('#'+_thingid).attr("data-state");
Comments
Post a Comment