jQuery jQuery.escapeSelector() method
Example
Use the .escapeSelector() method to escape the character "#" contained in an ID
<div>
<p id='#target'>Some text
p
<span id='target'>Some text
span
div
<script$(function(){//>will select id=#target
$
(
"
div
"
)
.
find
(
"
"
- $.
escapeSelector
(
"
#target
"
)
)
.
css
(
'
color
'
,
'
red
'
)
;
}
)
script
Try it »
Definition and Usage
The $.escapeSelector() function is used to escape characters or strings that have special meaning in CSS selectors.
**Tip:** 1. Added in jQuery 3.0, $.escapeSelector() can be used reliably in all browsers supported by jQuery.
2. This method is very useful when a CSS class name or an ID contains characters that have special meaning in CSS, such as a period or a semicolon.
Syntax
$
.escapeSelector( selector )
Parameters Description selector Selector: A string containing a selector expression to be escaped.
More examples
Select all elements with class .box inside a div
Selects all elements with class .box inside a div.
jQuery HTML/CSS methods