Javascript: function doesnt work even though condition is met (hard for me to explain)

welcome to StackOverflow.

You should take more precautions when writing your question, and make sure that it is written in good English, and in a way so that someone who does not priorly know what you want to achieve can understand your goal when reading the question.

I’m gonna try to answer to the parts I think I understand.

if the div has that class it then X function (in this case it’s fadeout) happens

What I understand is that you would like to trigger the execution of function X when the <div> receives a class (clicked?).

Watching a DOM element’s class value changes in Javascript is a problem that doesn’t seem to have a reliable solution. (See related questions.)

thus clicking on it makes X function happen.

Maybe your goal is actually simpler. If you only want to trigger the execution of a function when you click on the <div>, then you’ll have to look at mouse event handlers, especially .click() that allows to

Bind an event handler to the “click” JavaScript event

Leave a Comment