jQuery.escapeSelector()

jQuery.escapeSelector()

jQuery.escapeSelector( selector )Returns: Selector

Description: Escapes any character that has a special meaning in a CSS selector.

This method is useful for situations where a class name or an ID contains characters that have a special meaning in CSS, such as the dot or the semicolon.

The method is essentially a shim for the CSS Working Group's CSS.escape() method. The main difference is that $.escapeSelector() can be reliably used in all of jQuery's supported browsers.

Examples:

Escape an ID containing a hash.

$.escapeSelector( "#target" ); // "\#target"

Select all the elements having a class name of .box inside a div.

$( "div" ).find( "." + $.escapeSelector( ".box" ) );

© The jQuery Foundation and other contributors
Licensed under the MIT License.
https://api.jquery.com/jQuery.escapeSelector

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部