This seems very simple.. and still it does not work correctly.
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..
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.
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.
This is inside the style blok after the header
.highlight { color:black; background-color:yellow; }
.normal { color:white; background-color: blue; }
after this I have a script tag with a source of the latest jquery code http://code.jquery.com/jquery-latest.min.js
And after this a script blok and in here goes:
$(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");
});
});
And inside the body a p tag with an idname of "maindiv" and a class "normal"
with text click here.
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
Because I am an new user I can't enclose the snapshot of the complete code in here, but you can download it at: http://www.bckan.nl/temp/jquerybug.jpg