jQuery.escapeSelectorS2C Home « Attributes & Properties « .attr()

Escaping characters in CSS selectors.

Description

The jQuery.escapeSelector() method is used to escape characters with special meanings in a CSS selector.

The jQuery.escapeSelector() method was added in jQuery 3.0.

Syntax

Signature Description
jQuery.escapeSelector( selector )A class to look for.

Parameters

Parameter Description Type
selectorA string containing a CSS or jQuery selector.Selector

Return

A Selector object.

jQuery.escapeSelector( selector ) ExampleTop

Escape characters with special meanings in a CSS selector.

In the example below when we press the button the text is appended to '.div1' .


$(function(){
    $( "#" + $.escapeSelector( ".div1" ) ).append('We escaped the . Example 1 <br>');
    $( "div" ).find( "#" + $.escapeSelector( ".div1" ) ).append('We escaped the . Example 2 <br>');
});

div1. Some initial text.

Press the button below to action the above code: