Skip to content

Instantly share code, notes, and snippets.

@elijahmanor
Created March 3, 2012 04:11
Show Gist options
  • Save elijahmanor/1964301 to your computer and use it in GitHub Desktop.
Save elijahmanor/1964301 to your computer and use it in GitHub Desktop.
Find the jQuery Bug #8: Solution
<form id="personForm" name="personForm" method="post"
action="/Demo/jsf/main.jsf;jsessionid=0596FB948C236D0FFC16227FC10A0C23"
enctype="application/x-www-form-urlencoded">
<div class="field">
<label>Last Name</label>
<input id="personForm:lastname" name="personForm:lastname" type="text" value="" />
</div>
<div class="field">
<label>First Name</label>
<input id="personForm:firstname" name="personForm:firstname" type="text" value="" />
</div>
<div class="field">
<label>Address</label>
<input id="personForm:address" name="personForm:address" type="text" value="" />
</div>
<!-- ... more HTML ... -->
</form>
// <input id="person.name" name="person.name" type="text" />
$( "#person\\.name" ).addClass( "highlight" ); // Success
// <input id="person:name" name="person:name" type="text" />
$( "#person\\:name" ).addClass( "highlight" ); // Success
// <input id="person$name" name="person$name" />
$( "#person\\$name" ).addClass( "highlight" );​ // Success
String.prototype.escapeSelector = function() {
return this.replace( /([!"#$%&'()*+,./:;<=>?@\[\\\]^`{|}~])/g,
"\\$1" );
};
$( document ).ready( function() {
$( "#" + "personForm:firstname".escapeSelector() )
.addClass( "required" );
});
$( document ).ready( function() {
$( "#personForm\\:firstname" ).addClass( "required" );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment