Skip to content

Instantly share code, notes, and snippets.

@0x4a
Created June 1, 2014 04:19
Show Gist options
  • Save 0x4a/06afced51fb8a6857741 to your computer and use it in GitHub Desktop.
Save 0x4a/06afced51fb8a6857741 to your computer and use it in GitHub Desktop.
escape special characters in #css selectors - #js
/*
https://learn.jquery.com/using-jquery-core/faq/how-do-i-select-an-element-by-an-id-that-has-characters-used-in-css-notation/
The following function takes care of escaping these characters and places a "#" at the beginning of the ID string:
Example:
$( jq( "some.id" ) )
*/
function jq( myid ) {
return "#" + myid.replace( /(:|\.|\[|\])/g, "\\$1" );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment