Some text

">

Some text

" />
Easy Tutorial
❮ Misc Each Event Resize ❯

jQuery jQuery.escapeSelector() Method

jQuery HTML/CSS Methods

Example

Using the .escapeSelector() method to escape a character "#" in an ID.

<div>
    <p id='#target'>Some text</p>
    <span id='target'>Some text</span>
</div>
<script>
$(function () { 
    // Selects the element with id=#target
    $( "div" ).find( "#" + $.escapeSelector( "#target" )).css('color','red'); 
})
</script>

Definition and Usage

The $.escapeSelector() function is used to escape characters or strings that have special meanings in CSS selectors.

Note: 1. Added in jQuery 3.0, $.escapeSelector() can be reliably used in all browsers supported by jQuery.


Syntax

Parameter Description
selector Selector type A string containing a selector expression to be escaped.

More Examples

Select all elements with class .box inside a div


jQuery HTML/CSS Methods

❮ Misc Each Event Resize ❯