I have an element with id=”A B”. The following code fails:
<input type="text" id="A B">
<script>$("#A B").click(function(){alert();});</script>
The following code does not fail:
<input type="text" id="AB">
<script>$("#AB").click(function(){alert();});</script>
While it’s technically invalid to have a space in an ID attribute value in HTML (see @karim79’s answer), you can actually select it using jQuery.
See http://mothereffingcssescapes.com/#A%20B:
jQuery uses a Selectors API-like syntax, so you could use
$('#A\\ B');to select the element withid="A B".To target the element in CSS, you could escape it like this: