0

Code create element:

 function createimg(url_img){
    var create_img = document.createElement('img');
    create_img.setAttribute('class','imgg');
    create_img.setAttribute('src',url_img);
    document.getElementsByClassName('thumb')[0].appendChild(create_img);
}

Code Jquery: jquery is not working

$(document).ready(function(){
    $(".imgg").mouseover(function(){
        console.log('ok');
    });
});

I try with tag body is working fine:

$(document).ready(function(){
        $("body").mouseover(function(){
            console.log('ok');
        });
    });
  • Can u provide your html code too so we can help you – Harden Rahul Dec 02 '17 at 12:21
  • `createimg` is throwing an exception. See the [first linked question](https://stackoverflow.com/questions/10693845/what-do-queryselectorall-getelementsbyclassname-and-other-getelementsby-method)'s answers for why. I recommend that when doing web development, you keep your browser console open so you can see errors like that. – T.J. Crowder Dec 02 '17 at 12:22
  • But if you *didn't* have that bug, the problem would be as described in [the second linked question](https://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements). – T.J. Crowder Dec 02 '17 at 12:24
  • i use: $(document).on("mouseover",".imgg",function(){ console.log('ok'); }) and it working –  Dec 02 '17 at 12:46

0 Answers0