call jQuery function in <div> onload attribute - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:trigger

Description

call jQuery function in <div> onload attribute

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
   </head> 
   <body> 
      <div id="dynamic"></div>  
      <script>
$(function () {//from   w ww  .j  a v a2s . c o m
    var div = '<div onload="myfunction()">Here</div>' ;
    $("#dynamic").html(div);
    $('div[onload]').trigger('onload');
});

function myfunction(){
    console.log('Div is loaded ..');
}

      </script> 
   </body>
</html>

Related Tutorials