Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>getElementsByClassName</code> returns a <code>NodeList</code> (or an array if it's not built-in), but you're using it as though it were an <code>HTMLElement</code> by referring directly to a <code>style</code> property on it:</p> <pre><code>getElementsByClassName("editp").style.display ="none"; // here ------------------------^ </code></pre> <p>You should be seeing an error in the JavaScript console, since you're trying to retrieve the property <code>display</code> from <code>undefined</code> (since <code>getElementsByClassName("editp").style</code> will be <code>undefined</code>).</p> <p>If you want to act on the <em>first</em> matching element:</p> <pre><code>var elm = getElementsByClassName("editp")[0]; if (elm) { elm.style.display ="none"; } </code></pre> <p>...or if you want to act on all of them:</p> <pre><code>var index; var list = getElementsByClassName("editp"); for (index = 0; index &lt; list.length; ++index) { list[index].style.display ="none"; } </code></pre> <hr> <p><strong>Update</strong>:</p> <p>At some point, you edited the question and removed <code>var toggle = "off"</code> from the code (at global scope, just above the function) and made <code>toggle</code> an argument to <code>editToggle</code>. But you're not passing anything into <code>editToggle</code> according to your quoted markup, and even if you were, setting <code>toggle</code> to a new value within the function won't have any lasting effect if it's a function argument, as nothing refers to it after the function returns.</p>
 

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