Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a dynamically appended menu which I am removing if you click anywhere on page including the menu links itself. What I am trying to achieve is to prevent the remove if you click a specific link and that simply does not work for me. Unfortunately I cant use the delegate method, if that would help, due to old version on jquery used on client side, no option to update it.

So maybe you could suggest if there is any way to do so. Here is a quick example of mine.

<script>
            $(function() {

                $('.menu').append('<a href="" class="solid">Option</a> <a href="">Option</a> <a href="">Option</a>');                               

                $('.menu a').live('click',function(){
                    return false;
                });

                $('a.solid').live('click',function(){
                    return false;
                });

                $('html').click(function() {                    
                    $('.menu').remove();                
                });             

            });

        </script>

and the container

<div class="menu"></div>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
296 views
Welcome To Ask or Share your Answers For Others

1 Answer

Maybe it will work like this

$('html').click(function(e) {                    
   if(!$(e.target).hasClass('solid') )
   {
       $('.menu').remove();                
   }
}); 

see: http://jsfiddle.net/fq86U/2/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...