Dropdown Menu closed when we click all place

I have the following scripts in my dropdown menu:

<script type="text/javascript">

jQuery(window).load(function() {
    $("#nav > li > a").click(function () { // binding onclick
        if ($(this).parent().hasClass('selected')) {
            $("#nav .selected div div").slideUp(100); // hiding popups
            $("#nav .selected").removeClass("selected");
        } else {
            $("#nav .selected div div").slideUp(100); // hiding popups
            $("#nav .selected").removeClass("selected");

            if ($(this).next(".subs").length) {
                $(this).parent().addClass("selected"); // display popup
                $(this).next(".subs").children().slideDown(200);
            }
        }
    }); 
});
</script>

HTML

<div class="menu">
<span>
    <ul id="nav">
        <li><a href="#">Produk Teknik <i class='icons icon-right-dir'></i></a>
            <div class="subs">
                <div class="wrp3">
                    <ul>
                        <li><h3>Manometer</h3>
                            <ul>
                               <li><a href='#'>tes</a>
                                    <ul>
                                        <li><a href='#' class='anak'>tes-1</a></li>
                                    </ul>
                                </li>
                                <li><br /></li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </div>
        </li>
    </ul>
</span>

I need to change that script so that when we click all place, the dropdown menu will automatically be closed. Thank you

You can see my project example http://www.tokobesi.co.id/beta/

Answers


I think this is what you meant mate..Try this.. :)

$(document).click(function(e){
    if( $(e.target).closest(".menu").length > 0 ) {
        return false;
    }else{
        $("#nav .selected").removeClass("selected");
    }
});

Need Your Help

What is this component called?

iphone

http://itunes.apple.com/app/bloomberg/id281941097?mt=8

Best Way to Add Implied Multiplication (*) to a Python String?

python regex string

I know how to do this in other languages that are stronger with RegEx, but I'm not sure about Python. Basically what I'm trying to do is convert

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.