Manipulation: Support $el.html(selfRemovingScript) (#5378)
[jquery.git] / src / selector / escapeSelector.js
blob18c6591489766e270f731823adc360c3581c9567
1 import { jQuery } from "../core.js";
3 // CSS string/identifier serialization
4 // https://drafts.csswg.org/cssom/#common-serializing-idioms
5 var rcssescape = /([\0-\x1f\x7f]|^-?\d)|^-$|[^\x80-\uFFFF\w-]/g;
7 function fcssescape( ch, asCodePoint ) {
8         if ( asCodePoint ) {
10                 // U+0000 NULL becomes U+FFFD REPLACEMENT CHARACTER
11                 if ( ch === "\0" ) {
12                         return "\uFFFD";
13                 }
15                 // Control characters and (dependent upon position) numbers get escaped as code points
16                 return ch.slice( 0, -1 ) + "\\" + ch.charCodeAt( ch.length - 1 ).toString( 16 ) + " ";
17         }
19         // Other potentially-special ASCII characters get backslash-escaped
20         return "\\" + ch;
23 jQuery.escapeSelector = function( sel ) {
24         return ( sel + "" ).replace( rcssescape, fcssescape );