Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To manipulate an element from JavaScript you need to somehow get a reference to it, which can be done in numerous ways - without any context to go on I'd suggest your best option is to make sure your select element has an <code>id</code> attribute:</p> <pre><code>&lt;select id="myDropDown" name="whatever"&gt; &lt;option&gt;One&lt;/option&gt; &lt;option&gt;Two&lt;/option&gt; &lt;/select&gt; </code></pre> <p>...and then use <code>document.getElementById()</code>. Then to hide it you can update the appropriate style property:</p> <pre><code>document.getElementById("myDropDown").style.display = "none"; // OR document.getElementById("myDropDown").style.visibility = "hidden"; </code></pre> <p>Using <code>display:none</code> causes the browser to render the document as if the element didn't exist, i.e., it won't leave a space for it. Using <code>visibility:hidden</code> will make it invisible but there'll be an empty space on the page.</p> <p>There is more than one way to to test for a particular string on the page, but one way is just to get all the content via the body element's <code>innerHTML</code> or <code>textContent</code> (or, in IE <code>innerText</code>) properties and then use <code>.indexOf()</code>:</p> <pre><code>var searchString = "some string", pageContent = document.body.innerHTML; if (pageContent.indexOf(searchString) != -1) { document.getElementById("myDropDown").style.display = "none"; } </code></pre> <p>Where you place that code depends on when you want to do the test. You could put it in an <code>onload</code> handler if you want to do it without user input, otherwise put it in a click handler or something as appropriate.</p> <p>Demo: <a href="http://jsfiddle.net/n8uA9/" rel="nofollow">http://jsfiddle.net/n8uA9/</a></p>
    singulars
    1. This table or related slice is empty.
    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.
 

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