Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot change style of an array element with onClick
    text
    copied!<p>I'm having trouble with following code (it just wont change the top attribute :s)</p> <pre><code>var selectedDivs = new Array(); function addBorder(e) { if ($ctrlBeingpressed == true) { e.target.style.border="5px solid green"; // to show they are selected selectedDivs.push(e.target); } } function test(){ alert('changing position'); selectedDivs[0].style.top="10px"; } &lt;button type="button" onclick="test()"&gt;Right&lt;/button&gt; </code></pre> <p>Some generated HTML (addBorder is called in Onclick on one of the DIV's here):</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; … &lt;/head&gt; &lt;body style="position: absolute; cursor: auto;" application"="" onkeyup="clearPress()&gt; &lt;div id=" onkeydown="controlCheck(event)"&gt; &lt;div id="accordion" class="ui-accordion ui-widget ui-helper-reset" style="position:absolute;top:0px;left:0px;width:300px;height:900px" role="tablist"&gt; … &lt;/div&gt; &lt;div id="buttons" style="position:absolute;top:0px;left:315px;width:1100px;height:50px;border:2px solid grey"&gt; … &lt;/div&gt; &lt;div id="canvas" class="DROPPABLE ui-droppable" style="position:absolute;top:50px;left:315px;width:1100px;height:850px;border:2px solid grey"&gt; &lt;div class="DRAGGABLE ui-widget-content ui-draggable" style="border: 1px solid red; width: 120px; height: 60px; top: 156.117px; left: 188.117px; position: relative;" onclick="addBorder(event)"&gt; &lt;img id="PMF00" src="/devices/AAU01-010.gif" style="border: 5px solid green;"&gt;&lt;/img&gt; &lt;/div&gt; &lt;div class="DRAGGABLE ui-widget-content ui-draggable" style="border: 1px solid red; width: 120px; height: 60px; top: 10px; left: 10px; position: relative;" onclick="addBorder(event)"&gt; &lt;img id="PMF01" src="/devices/AAU01-010.gif"&gt;&lt;/img&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&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