0

I tried to call jQuery function in div onload method but it is not working here is my html code for calling the function in

<div onload="myfunction(value)">
</div>

and this function is call in jQuery but not working properly.

Here is my jQuery function calling:

<script type="text/javascript">
    $(document).ready(function() {
        myfunction(value) {
            alert(value);
        }
    });
</script>

Please give me an idea about that how to call function in div load method

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Vishal Patel
  • 49
  • 1
  • 6

1 Answers1

0

Example shows Div is loaded

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
    <div id="dynamic"></div>
</body>
<script>
$(function () {
    var div = '<div onload="myfunction()">Here</div>' ;
    $("#dynamic").html(div);

    $('div[onload]').trigger('onload');
});

function myfunction(){
    alert('Div is loaded ..');
}
</script>
</html>
Aman Kumar
  • 4,533
  • 3
  • 18
  • 40