Add Style on image object using JavaScript in Canvas -


i'm trying add z-index on image. used setattribute style not working. please figure out issue

// hero image var heroready = false; var heroimage = new image(); heroimage.onload = function () {     heroready = true; };  heroimage.setattribute("src", "img/car.png"); heroimage.setattribute("style", "z-index:5;"); 

you should use "style". https://developer.mozilla.org/en-us/docs/web/api/htmlelement/style

heroimage.style.zindex = "5"; 

here's an example play with.

snippet:

var div = document.getelementbyid("something");  div.style.position = "absolute";  div.style.width = "200px";  div.style.height = "200px";  div.style.backgroundcolor = "blue";  div.style.zindex = "2";    function onclick() {    (div.style.zindex == "2") ? div.style.zindex = "0" : div.style.zindex = "2";  }
#another {    z-index: 1;    width: 180px;    height: 180px;    background-color: green;    position: absolute;  }    button {    margin-left: 200px;  }
<div id="something">something</div>  <div id="another">another</div>  <button onclick="onclick()">change zindex</button>


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -