javascript - Get attribute during .on event in Jquery -
so, have 10 links this: <a href="#" data-test="test" class="testclass"></a>
, on function. this:
$(document).on("click", ".testclass", function () { alert($(this).attr('data-test')); });
i cannot understand how can data-test attribute specific tag in case. $(this)
returns document
object , not a
you have bind listener anchor, not document:
$('a.testclass').on('click', function() { alert($(this).data('test')); })
and data function right way info attached dom element.
javascript jquery
No comments:
Post a Comment