Some text

">

Some text

" />
Easy Tutorial
❮ Eff Show Event Stoppropagation ❯

jQuery jQuery.escapeSelector() Method

jQuery HTML/CSS Methods

Example

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

<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 with 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

❮ Eff Show Event Stoppropagation ❯