I would be very surprised if jQuery 1.4.2 is wrong. jQuery 1.4.2 is not mistaken. hasClass("fixed") must be true in both cases in all versions of jQuery. Here is an example using v1.6.1, and the same example using v1.4.2. Both work fine.
If you want to verify that the βfixedβ class is only for an element that is easier to do without jQuery by going directly to the reflected property:
if (this.className === "fixed") {
className is a property that reflects the class attribute, and like the class attribute, it is a space-delimited string.
The foregoing, of course, will not succeed if the element has another class on it, for example, "fixed something-else".
If you specifically want to verify that it has a "fixed" and no "chkCol", then you must do this on purpose:
var $this = $(this); if ($this.hasClass("fixed") && !$this.hasClass("chkCol")) {
If you did this in the selector (instead of checking the element that you already had), you can use the selector ".fixed:not(.chkCol)" . But although you can do this with an element that you already have is , it is unnecessarily expensive (jQuery must parse the selector).
Refresh . You said you tried the && !$this.hasClass("chkCol") thing, and it didn't work. This means that something earlier in the if condition already defined the result of the expression as a whole, and therefore the result of the !$this.hasClass("chkCol") does not matter (and the circuit does not start at all).
Example:
var x = 1; if (x == 1 || $this.hasClass("fixed") && !$this.hasClass("chkCol"))
In this case, since x - 1 , nothing to the right of || not even visible; the value of the expression is already true .
Update 2 :
You said you were using hasClass , but in a comment on another answer, you said:
If I use $(this).attr('class') == "fixed" then it does not enter at all if the condition
I do not think that you are actually doing this:
if ($(this).attr('className') == "fixed") {
Note that "className", not "class". If this is what you are doing, then it will not work on 1.6.1, but it will be on 1.4.2. There is no attribute called "className"; there is an attribute called "class" and a property of "className". jQuery 1.6.x distinguishes between attributes and properties.
My code above using hasClass will work on all versions. Or change your code to use attr("class") rather than attr("className") .
Here's an example v1.4.2 showing attr("className") working (which it shouldn't). Here's an example v1.6.1 showing attr("className") does not work (which is correct). Both versions show the correct way to get the "class" attribute.