File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes jquery attribute selector = vs != Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "jquery attribute selector = vs !=" Watch "jquery attribute selector = vs !=" New topic
Author

jquery attribute selector = vs !=

Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30789
    
157

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, TOGAF part 1 and part 2
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30789
    
157



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 ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61448
    
  67

Can you post an SSCCE that exhibits the behavior?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30789
    
157

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: 15376
    
    6
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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30789
    
157

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: 15376
    
    6
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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30789
    
157

Ugh. Ok thanks. It's odd that it works for !=.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61448
    
  67

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: jquery attribute selector = vs !=