Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

jquery attribute selector = vs !=

 
author & internet detective
Posts: 39790
797
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jeanne Boyarsky
author & internet detective
Posts: 39790
797
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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.
 
Marshal
Posts: 67344
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post an SSCCE that exhibits the behavior?
 
Jeanne Boyarsky
author & internet detective
Posts: 39790
797
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39790
797
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39790
797
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ugh. Ok thanks. It's odd that it works for !=.
 
Bear Bibeault
Marshal
Posts: 67344
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Can you smell this for me? I think this tiny ad smells like blueberry pie!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!