javascript - jquery call a function when button element in a specific id is clicked -


i call function when button pressed within particular table.

this works call function when button pressed anywhere

$(document)   .on('click', 'button', fuction(){    ...   }); 

but in more specific case.

$(document)   .on('click', '#imgpreviewtable.button', function(){     ...        }); 

i know can set buttons call function independently need way. appreciated.

here example

html code:

<table id="mytable"> <thead> <tr><th>buttons</th></tr> </thead> <tbody> <tr><td><input type="button" class="tblbutton" value="button 1"></td></tr> <tr><td><input type="button" class="tblbutton" value="button 2"></td></tr> <tr><td><input type="button" class="tblbutton" value="button 3"></td></tr> </tbody> </table> 

javascript code

$('#mytable tblbutton').on('click',function(){ alert($(this).val()); }) 

result alert value of button have clicked


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -