Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6789119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:33:57+00:00 2026-05-26T17:33:57+00:00

How can I do that? event.target returns a HTML object, and my element is

  • 0

How can I do that?

event.target returns a HTML object,

and my element is a jQuery object.

Is there a better way to find out if event.target = my_jquery_object, besides comparing IDs or classes?

I want to make sure that it’s the same object, not just a element with a similar class…

I tried with $(event.target) !== the_element and it fails

the_element is defined at the begining as $('.something', $(this))


What I am trying to do is to make a box close when the user clicks outside of it, but with the condition that the click wasn’t made on the link that opened the box in the first place.

So I have this:

$(document).click(function(event){
  if(($(event.target).parents().index(box) == -1) 
    && box.is(':visible')){
      close(); 
  }

});

And I want to add another condition that verifies that the click wasn’t made on the link that opened the box.

This works, but I don’t like it:

if($(event.target).attr('id') != the_element)

🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:33:58+00:00Added an answer on May 26, 2026 at 5:33 pm

    You can get the actual DOM element from the jQuery using .get(0) or simply the_element[0]. It would probably be better to check with jQuery, though.

    if (the_element.is(event.target))
    {
        ...
    }
    

    Using your example:

    $(document).click(function(event){
      if (the_element.is(event.target)) {
          return false;
      }
      if(($(event.target).parents().index(box) == -1) 
        && box.is(':visible')){
          close(); 
      }
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It can be anoying that jQuery event handlers always execute in the order they
Is there an event that I can tap into in Global.asax to execute some
Is there a client event that I can use for when a DropDownList's data
Does jquery/javascript have any event model that you can attach to your objects? Basically
Maybe I'm just an idiot, but I can't seem to find an event that
With event delegation in jQuery 1.6, you can respond to events that have bubbled
I want to have a generic event that I can fire that will take
How do I create a C# event handler that can be handled in IronPython?
How can I launch an event that has accessors like this : public event
I needed a generic collection or list that can fire an event when an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.