aspose file tools
The moose likes HTML, CSS and JavaScript and the fly likes JQuery Element ID Question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "JQuery Element ID Question" Watch "JQuery Element ID Question" New topic
Author

JQuery Element ID Question

Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15230

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

Joined: Jan 10, 2002
Posts: 56178
    
  13

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.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15230

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

Joined: Jan 10, 2002
Posts: 56178
    
  13

You can escape the dot, but it's pretty ugly:

Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
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.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15230

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://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: JQuery Element ID Question
 
Similar Threads
onclick two function calls
Convert prototype ajax to jquery
101 jQuery
JQuery: How to get the value updated in a javascript file
Inner HTML not running JavaScript