javascript - Selecting an element by class, then moving it -


i need select div it's classname.

after selecting it, need move 100 pixels.

here i've tried far:

html

<div  style="z-index:101;  position: absolute;  left: 0px; top: 300px; width: 20px; height:450px; padding: 0px; border: 0px;" class="wrapper" >content</div> 

js

var class = document.getelementbyclassname("wrapper"); var div = class[0]; div.style.top = '100px'; 

not sure if i'm understanding nodelists correctly.

jsfiddle

1. missing s in getelementsbyclassname() ;

2. used class variable name, reserved word. name else.

3. move up, change .style.top property (300-100 = 200px).

fixed code:

var wrapper = document.getelementsbyclassname("wrapper");  var div = wrapper[0];  div.style.top = '200px';
<div  style="z-index:101;  position: absolute; left: 0px; top: 300px; width: 20px; height:450px; padding: 0px; border: 0px;" class="wrapper" >content</div>


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -