mps_sudip
mps_sudip

Reputation: 49

Jquery parents() are not working properly

Use this jquery code:

$(document).ready(function() {
            $("#origin").live("click",function(e){
                e.preventDefault();
                $("#rest").toggle(200);
            });
            $("body").click(function(e){
                if($(this).parents("#rest").length<=0)
                {
                    $("#rest").hide(200);
                }
            });
        });

But when I click in inside the div id="rest" then the rest div hide. what the coding problem is?

Upvotes: 0

Views: 692

Answers (2)

Imran Subhani
Imran Subhani

Reputation: 1104

There is a syntax error so please change this:

if($(this).parents("#rest").length<=0)

to:

if($(this).parent("#rest").length<=0)

I think you may be want to do this:

if($(this).parent().length<=0)

Upvotes: 0

Sarfraz
Sarfraz

Reputation: 382881

Change this:

if($(this).parents("#rest").length<=0)

To:

if($("#rest").is(":visible"))

More info: http://api.jquery.com/visible-selector/

Upvotes: 1

Related Questions