Does anyone know how to select an item in the DOM by ID with jQuery, when that ID has a space?
For example, the ID of my item would be
<div id="content Module">Stuff</div>
How would I select this with jQuery?
If I just do
$("#content Module").whatever()
jQuery will try to find an item with both the ID of content and the ID of Module, which is not what I am looking for.
I should add that I am working with an old code base where these two word ids are used extensively, so going through and changing all the IDs would be bad.
Escaping any misc character on selector (along with spaces).
The method Chris suggested can likely be adapted to work with jQuery functions.
Don't use spaces, the reason for this is simple, space character is not a valid for ID attribute.
But if you don't care about standards try
$("[id='content Module']")
Similar thread > What are valid values for the id attribute in HTML?
Edit: How id differs in between HTML 4.01 and HTML5
Link: http://mathiasbynens.be/notes/html5-id-class
this can work if you want the element have the exact value for the id
but if you want to check if element have only one of them ( just like class ) with or without other ids
this will select the element if it has
id="content"
orid="content Module"
orid="content Module other_ids"
An idea to try:
The semicolon may cause a javascript error. I also recommend changing the ID to not have any spaces.
Also, try
document.getElementByID("content Module")