javascript - How can I remove the append h2 tag after open class comes. I am trying, but not work -
<ul class="nav" id="yui_3_17_2_3_1433409929526_470"> <li class="dropdown open" id="yui_3_17_2_3_1433409929526_469"> <a href="http://192.168.1.112/mth_old_31/moodle28/message/index.php?viewing=recentconversations" class="dropdown-toggle" data-toggle="dropdown" title="unread messages (5)" id="yui_3_17_2_3_1433409929526_473"> <span id="yui_3_17_2_3_1433409929526_472">5</span> <i class="fa fa-envelope"></i> </a> <ul class="dropdown-menu"> <li class="open"><a title="admin user will..." href="http://192.168.1.112/mth_old_31/moodle28/message/index.php?user1=2&user2=4"> <div class="message unread"> <span class="msg-picture"> <img src="http://192.168.1.112/mth_old_31/moodle28/theme/image.php?theme=elfin28&component=core&image=u%2ff1" alt="picture of student user" title="picture of student user" class="userpicture defaultuserpic" width="60" height="60"> </span> <span class="msg-body"> <span class="msg-time"> <i class="fa fa-comments"></i> </span> <span class="msg-sender">student</span> <span class="msg-text">admin user will...</span> </span> </div> </a> </li> </ul> <h2 id="myid" class="box-messages">massage</h2> </li> <div class="block_action" id="yui_3_17_2_3_1432698699754_495"> <input type="image" class="moveto customcommand requiresjs" alt="move dock" title="dock block" src="http://192.168.1.112/mth_old_31/moodle28/theme/elfin28/pix/arrow.png" id="yui_3_17_2_3_1432698699754_494"> </div> </ul> <script> $("#box1 ul.nav li.dropdown").append('<h2 id="myid" class="box-messages">massage</h2>'); $( "#box1 ul.nav li.dropdown.open span" ).click(function() { $( "h2#myid" ).remove();}); </script>
i trying not working. working plz help
you need use event delegation selector has evaluated later
$("#box1 ul.nav").on('click', 'li.dropdown.open span', function () { $("#myid").remove(); });
in case when using $( "#box1 ul.nav li.dropdown.open span" )
li
don't have open
class click handler not registered.
Comments
Post a Comment