JQuery escapeSelector() Method Last Updated : 25 Jul, 2024 Comments Improve Suggest changes Like Article Like Report The escapeSelector() method in jQuery is used to escape CSS selectors which have special significant character or string. It can select the element of id('#ID1', '#ID2') and elements of class('.class1', '.class2'). Let us understand it with the help of few examples. Syntax:jQuery.escapeSelector( selector )Parameters: This method accepts single parameter selector that holds a string which contains a selector expression to escape (example '#ID1' etc).Example 1: This example selects elements of class = '.list'. html <!DOCTYPE HTML> <html> <head> <title> jQuery escapeSelector() method </title> <script src= "https://code.jquery.com/jquery-3.5.0.js"> </script> <style> li { width: 150px; margin: 0 auto; } .highlight { background-color: green; } </style> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksForGeeks </h1> <p id="GFG_UP"></p> <ul> <li class=".list">GFG_0</li> <li class=".list">GFG_1</li> <li class="list">GFG_2</li> <li class="list">GFG_3</li> <li class=".list">GFG_4</li> </ul> <br> <button onclick="Geeks()"> Click here </button> <p id="GFG_DOWN"></p> <script> var elUp = document.getElementById("GFG_UP"); var elDown = document.getElementById("GFG_DOWN"); elUp.innerHTML = "JQuery | escapeSelector() method"; function Geeks() { $("ul").find("." + $.escapeSelector( ".list")).addClass("highlight"); elDown.innerHTML = "The list elements of class" + " '.list' are highlighted not the " + "elements of class 'list'"; } </script> </body> </html> Output:Example 2: This example selects elements of ID = '#list' html <!DOCTYPE HTML> <html> <head> <title> jQuery escapeSelector() method </title> <script src= "https://code.jquery.com/jquery-3.5.0.js"> </script> <style> li { width: 150px; margin: 0 auto; } .highlight { background-color: green; } </style> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksForGeeks </h1> <p id="GFG_UP"></p> <ul> <li id="#list">GFG_0</li> <li>GFG_1</li> <li>GFG_2</li> <li>GFG_3</li> <li id="list">GFG_4</li> </ul> <br> <button onclick="Geeks()"> Click here </button> <p id="GFG_DOWN"></p> <script> var elUp = document.getElementById("GFG_UP"); var elDown = document.getElementById("GFG_DOWN"); elUp.innerHTML = "JQuery | escapeSelector() method"; function Geeks() { $("ul").find("#" + $.escapeSelector( "#list")).addClass("highlight"); elDown.innerHTML = "The list element of id" + " '#list' is highlighted not the" + " element of id 'list'"; } </script> </body> </html> Output: Comment More infoAdvertise with us Next Article JQuery escapeSelector() Method P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies JQuery jQuery-Methods Similar Reads jQuery detach() Method The detach() is an inbuilt method in jQuery that removes the selected elements from the DOM tree including all text and child nodes but it keeps the data and the events. Document Object Model (DOM) is a World Wide Web Consortium standard. This defines accessing elements in the DOM tree. Syntax: $(se 1 min read jQuery contents() Method The contents() is an inbuilt method in jQuery that returns all the direct children, including text and comment nodes for the selected element. Syntax: $(selector).contents()Parameter: It does not accept any parameter. Return Value: It returns all the direct children elements of the selected element. 2 min read jQuery | Misc get() Method The get() Method in jQuery is used to get the DOM element specified by the selectors. Syntax $(selector).get(index) Parameters: This method accepts single parameter index which is optional. It is used to specify which of the matching elements to get by its index number. Example 1: This example uses 1 min read Lodash _.escape() Method Lodash _.escape() method is used to convert the characters "&", "<", ">", '"', and "'" of the given string into their corresponding HTML entities. Syntax:_.escape([string='']);Parameter:string: This parameter holds the string containing escape characters.Return Value: This method returns t 1 min read jQuery Event Methods Complete Reference An event refers to the actions performed by the site visitor during their interactivity with the website (or webpage). There can be various types of events such asThe user clicks on the button.The user moves the mouse pointer over an image.The user pressed any key from the keyboard, etc.Syntax:$(sel 6 min read Like