Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JQuery Element ID Question

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The majority of the elements in my pages have id's like

foo.hoo

However, JQuery tends to not like this with respect to

$('#foo.hoo')

It doesn't error out, it just doesn't grab the element. Is there anyway around this?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jQuery is following CSS which doesn't allow for dots in id names. It kinda sucks cause I like using dots for name-spacing ids, but that precludes their use in CSS and jQuery.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
jQuery is following CSS which doesn't allow for dots in id names. It kinda sucks cause I like using dots for name-spacing ids, but that precludes their use in CSS and jQuery.


Yea, I just searched the JQuery mailing list and discovered the same thing. Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can escape the dot, but it's pretty ugly:

 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, basically the dot is used to denote a CSS class name in a selector. The only way around is to do how Bear proposes, i.e. to escape the dot.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a big ugly but its not too bad and it's less intrusive than the work around. Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic