Note that there are some explanatory texts on larger screens.

plurals
  1. POusing addClass or toggleClass with JQuery inside a click method does not work? bug?
    primarykey
    data
    text
    <p>This seems very simple.. and still it does not work correctly.</p> <p>I got it working if you put the class .normal above the .hightlight.. but i don't alter the style here.. only the position. This does not make any sense..</p> <p>I can't seem to paste the html code in here, so i have to do it in blocks. And I enclosed a snapshot of all the code.</p> <p>Make sure you have an empty html page. The doctype does not matter.. I tested it on different doctypes, but it still does not work correctly.</p> <p>This is inside the style blok after the header</p> <pre><code>.highlight { color:black; background-color:yellow; } .normal { color:white; background-color: blue; } </code></pre> <p>after this I have a script tag with a source of the latest jquery code <a href="http://code.jquery.com/jquery-latest.min.js" rel="nofollow">http://code.jquery.com/jquery-latest.min.js</a></p> <p>And after this a script blok and in here goes:</p> <pre><code>$(document).ready(function () { $('#maindiv').css('cursor', 'pointer'); $('#maindiv').click(function () { //alert("click"); // $(this).toggleClass("highlight"); //this does not work! // $(this).addClass('highlight'); //this does not work! // $(this).attr("class", "highlight"); //this works // $(this).css("background", "yellow"); this works // the javascript way to do this works also fine. // var element = document.getElementById('maindiv'); // element.setAttribute("class", "highlight"); }); </code></pre> <p>});</p> <p>And inside the body a p tag with an idname of "maindiv" and a class "normal"</p> <p>with text click here.</p> <p>Oke, I can't wait until someone try this too.. it's crazy, because all other way's work. But only the .addClass and .toggleClass don't work correctly</p> <p>Because I am an new user I can't enclose the snapshot of the complete code in here, but you can download it at: <a href="http://www.bckan.nl/temp/jquerybug.jpg" rel="nofollow">http://www.bckan.nl/temp/jquerybug.jpg</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload