0

I am listening to clicks on an element with a specific class. When I click inside this element I want to get this element, not the children I clicked on. How do I avoid getting children back when I call

event.target

Here is fiddle I created to demonstrate the problem https://jsfiddle.net/yxvfgkcs/

Since I get children back they get CSS applied to them instead of the parent.

How do I figure out I have clicked on a child of element and get the element with class selectable back?

1 Answer 1

1

Since you're already using jQuery you can use .closest():

var clickedField = $(e.target).closest(".selectable");

See updated JSFiddle

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.