| Author |
jquery attribute selector = vs !=
|
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 23645
|
|
I'm puzzled by the output of these. I get:
9
7
0
I thought = and != were opposites as selectors. The fact that != works implies it is in fact checking for the value 2 and spaces or the like aren't messing it up. I've created the third one by copy pasting the working line and removing the exclamation point so I know it isn't a typo. Any ideas what is going on here?
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 23645
|
|
I have a workaround that lets me proceed, but no insight to why. The above returns 2. (9-7). Which is correct. But it seems like it should be exactly the same as the = selector.
|
 |
Bear Bibeault
Author and opinionated walrus
Marshal
Joined: Jan 10, 2002
Posts: 50693
|
|
|
Can you post an SSCCE that exhibits the behavior?
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 23645
|
|
Yes. I didn't include one before because I thought it would be obvious. After all, I'm sure the = selector works as it should.
The following example displays:
2 - expected
1 - expected
0 - the problem
1- expected
I'm on Mac Lion/Safari. Same behavior on Mac Lion/Chrome. This is from a proof of concepts for robotics (not work) so I didn't spend the time getting every shred of "business" meaning out of it.
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15003
|
|
Maybe this will make you understand what is happening
http://jsfiddle.net/2DFA2/ [Needs console open]
Compare the initial load vs the button click with the logs. Notice anything?
Eric
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 23645
|
|
I notice that != looks like it uses the udpated values and = does not. And that jfiddle is cool.
This doesn't help though as I still don't see why. Or even if that is the problem.
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15003
|
|
The value property does not get updated when the value changes, hence why the selector fails. I think there is a jQuery bug logged for this. You need to use filter()
http://jsfiddle.net/2DFA2/1/
Eric
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 23645
|
|
|
Ugh. Ok thanks. It's odd that it works for !=.
|
 |
Bear Bibeault
Author and opinionated walrus
Marshal
Joined: Jan 10, 2002
Posts: 50693
|
|
Eric Pascarello wrote:The value property does not get updated when the value changes ...
Actually, the value property does update when the control value is changed; it's the value attribute that doesn't change, and that, of course, is what the CSS selector is checking against.
|
 |
 |
|
|
subject: jquery attribute selector = vs !=
|
|
|