Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem is due to HTML entities; the "<strong><code>&amp;lt;</code></strong>" is seen by the browser as "<strong><code>&lt;</code></strong>".</p> <p>The same could be said for the example provided by bobince; please note that the following does not work with jQuery 1.32 on Win + FF3:</p> <pre><code>var select= document.getElementById('SomeDropdown'); for (var i= select.options.length; i--&gt;0;) { if (select.options[i].value=="a'b]&amp;lt;p&gt;") { alert('found it'); } } </code></pre> <p>However, changing the entity to a literal will indeed find the desired value: </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;") { alert('found it'); } } </code></pre> <p>Of course, there is a problem here, as the value that you're specifying is not the exact value that you're looking for. This can also be corrected with the addition of a helper function:</p> <pre><code>function html_entity_decode(str) { var decoder = document.createElement('textarea'); decoder.innerHTML = str; return decoder.value; } </code></pre> <p>All together now:</p> <pre><code>var srcValue = html_entity_decode("a'b]&amp;lt;p&gt;"); var select= document.getElementById('SomeDropdown'); for (var i= select.options.length; i--&gt;0;) { if (select.options[i].value == srcValue) { alert('found it'); } } </code></pre> <p>Any now, the input value that you're searching for exactly matches the value of the select element.</p> <p>This can also be written using jQuery methods:</p> <pre><code>var srcValue = html_entity_decode("a'b]&amp;lt;p&gt;"); $($('#SomeDropdown').attr('options')).each(function() { if (this.value == srcValue) { $(this).remove(); } }); </code></pre> <p>And then finally, as a plugin since they are so easy to make:</p> <pre><code>jQuery.fn.removeByValue = function( val ) { var decoder = document.createElement('textarea'); decoder.innerHTML = val; var srcValue = decoder.value; $( $(this)[0].options ).each(function() { if (this.value == srcValue) { $(this).remove(); } }); return this; }; $('#SomeDropdown').removeByValue("a'b]&amp;lt;p&gt;"); </code></pre>
 

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