javascript - passing event data dynamically in jquery -


please refer below html

<div class="icon">                 <span>                         <img src=""/>                     </span>              </div> 

i adding class "bootstrap-modal" dynamically above img tag when clicked.

$(".icon img").on("click", function (e) {             var data="some object";                  $(this).addclass("bootstrap-modal");     }); 

then have 1 more click event bootstrap-modal class below

$(document).on('click',"bootstrap-modal" function (e,data) {  //here need data object  }); 

how pass data object img click event bootstrap-modal click event?

that means need values previous click handler ? how can ?

save in data:

$('.icon img').on('click', function(e) {     var data = 'some object';     $(this).addclass("bootstrap-modal").data('test', data); });  $('.icon').on('click', '.bootstrap-modal', function(e, data) {     var data = $(this).data('test'); }); 

fyi: since use newest version of jquery, you'd better use on method event delegation instead of deprecated live. here .icon supposed static parent element of .bootstrap-modal.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -