0

new to web.

I am trying to know if user has clicked on div with css a certain class

my class html element is as follows

<div class="icon arrowIcon arrowLight tagIcon"></div>

my event target value is

$(event.target): jQuery.fn.init[1]
   0: div.icon arrowIcon arrowLight tagIcon

and the function

($(event.target).find('.tagIcon').length > 0)

returns false.

Any idea?

2 Answers 2

6

find searches the children. You should check if your element has the class you want:

$(event.target).hasClass("tagIcon")
Sign up to request clarification or add additional context in comments.

Comments

3

find() finds matching element(s) inside the element it is called on. It does not matter if the element itself matches the selector.

Change your check to:

($(event.target).is('.tagIcon'))

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.