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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -