Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run my jquery code on div that inserted form jquery code?

I need your help in my code I have problem when new div inserted from jquery the inserted div does not apply to my jquery code if anyone have solution please tell me and this my Html code

<input type="text" id="t" value=""/>
<a href="#" class="btn">click</a><br/>
<br/>
<div  class="profileInfoSectionwall"style="border:1px solid #ccc">
text111111

    <div class="remove" style="display: none;">
        <a class="post_remove" rel="1" herf="#">X</a>
    </div>
</div>
<br/>
<div  class="profileInfoSectionwall"style="border:1px solid #ccc">
text222222

    <div class="remove" style="display: none;">
        <a class="post_remove" rel="2" herf="#">X</a>
    </div>
</div>

and this jquery code

  $(document).ready(function(){
$(".profileInfoSectionwall").mouseenter(function(){
         $(this).children(".remove").show();

     });
     $(".profileInfoSectionwall").mouseleave(function(){
             $(".remove").hide();

         });

    $(".btn").click(function(){
         var s=$("#t").attr("value");
        $(this).after("<br/><br/><div class='profileInfoSectionwall' style='border:1px solid #ccc'>"+s+"<div class='remove' style='display: none;'><a class='post_remove' rel='3' herf='#'>X</a></div></div>");
    return  false;


    })



})

thanks in advance

like image 493
Shady Mohamed Avatar asked Dec 27 '22 05:12

Shady Mohamed


1 Answers

You may want to try using the .on method so something like:

$(".profileInfoSectionwall").on('mouseenter', function(){
     $(this).children(".remove").show();

});

$(".profileInfoSectionwall").on('mouseleave', function(){
    $(".remove").hide();
});
like image 176
SS44 Avatar answered Apr 19 '23 23:04

SS44