javascript - JQuery hasClass - why does it always return false in this case? -
I have a span with a background image, which I want to make between the click plus plus minus background image I am I want to add and remove the class 'Open' to do this: My period looks like this ...
And my JQuery looks like this ...
$ (function () {$ ('expand'). ) {If ($ (this) .hasClass ('open')) {$ (this) .removeClass ('open');} and {$ (this) .addClass ('open');}})}} ;
The behavior I am getting is that this class will add 'Open', but after repeated click it will not be deleted again. Logging in to the console has been shown that if my statement is always evaluating false.
I have considered using the toggle class but have not done so because it is working once, hide the content block.
Edit because people are focusing on my CSS, I will also provide it. (SASS / SCSS):
. Expand {Background: URL (/images/plus-minus-orange.gif) Top Center No Repetition; Display area; Height: 21px; Margin: 0 auto; Width: 22px; & Amp;. Open {background: url (/images/plus-minus-orange.gif) not center-repeat; }}
Can I also add that the duration is being displayed correctly and is clickable, and I have not created this problem with the simplified version of the code.
Your Bela works fine for me Just add some text to span
So that you can actually click on span
.
& lt; Span class = "open expansion" & gt; Some text here & lt; / Span & gt;
Comments
Post a Comment