javascript - Data-toggle and onclick doesn't work together and i'm too new to apply @epascarello 's solution to -
i have problem little bit 1 :
jquery onclick doesn't work on button data-toggle , data-target
but can't apply solution @epascarello problem
i'm using bootstrap , want add collapse , onclick action on same < a>
<a class="control" data-toggle="collapse" data-target="#demo"onclick="play('audioplayer', this)">
if delete data-toggle part, onclick works, , if delete onclick part, data-toggle works,
could me ?
thank :)
first give id a tag
<a id="yourid" class="control" data-toggle="collapse" data-target="#demo"onclick="play('audioplayer', this)">
and js
$(document).on("click", "#yourid", function() { alert("test"); });
try first
this called delegated event handlers .you can refer to: http://api.jquery.com/on/
explanation
with delegated event handlers, attach event handlers
parent
element exists @ time run code (it's document
in case). when child elements clicked (no event handlers), event bubbled browser , handled parent (with event handlers attached)
delegated events have advantage can process events descendant elements added document @ later time. picking element guaranteed present @ time delegated event handler attached, can use delegated events avoid need attach , remove event handlers
Comments
Post a Comment