user2841574
user2841574

Reputation:

if ID does not match x or children of x

I have a div with an id and I also have a piece of jQuery code to detect if the relatedTarget's id does not match the divs id. This itself works fine, but I also don't want it to match any children of said div either.

The HTML is similar as follows...

    <div id="a">
        <div id="b">
            <img src="..." />
        </div>
    </div>

The jQuery code is similar as follows...

    if(e.relatedTarget.prop('id') != 'a') {

Of course the if statement will return true if the relatedTarget points to children of div#a which is not what I want.

Any ideas how I would go about fixing this? Thanks.

Upvotes: 0

Views: 43

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388316

Try

if($(e.relatedTarget).closest('#a').length == 0) {

Upvotes: 2

Related Questions