Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't think you can. It <em>should</em> be:</p> <pre><code>#SomeDropdown &gt;option[value='a\'b]&lt;p&gt;'] </code></pre> <p>And this does work as a CSS selector (in modern browsers). Expressed in a JavaScript string literal you would naturally need another round of escaping:</p> <pre><code>$("#SomeDropdown &gt;option[value='a\\'b]&lt;p&gt;']") </code></pre> <p>But this doesn't work in jQuery because its selector parser is not completely standards-compliant. It uses this regex to parse the <code>value</code> part of an <code>[attr=value]</code> condition:</p> <pre><code>(['"]*)(.*?)\3|)\s*\] </code></pre> <p>\3 being the group containing the opening quotes, which weirdly are allowed to be multiple opening quotes, or no opening quotes at all. The .*? then can parse any character, <em>including quotes</em> until it hits the first ‘]’ character, ending the match. There is no provision for backslash-escaping CSS special characters, so you can't match an arbitrary string value in jQuery.</p> <p>(Once again, regex parsers lose.)</p> <p>But the good news is you don't have to rely on jQuery selectors; there are perfectly good DOM methods you can use, in particular HTMLSelectElement.options:</p> <pre><code>var select= document.getElementById('SomeDropdown'); for (var i= select.options.length; i--&gt;0;) { if (select.options[i].value=="a'b]&lt;p&gt;") { // do something with option } } </code></pre> <p>This is many times simpler and faster than asking jQuery to laboriously parse and implement your selector, and you can use any value string you like without having to worry about escaping special characters.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload