javascript - Get ID of a random div by using an array -


i'm trying create right-click function javascript, thought use mouseover function, e.g.:

mysterydiv.onmouseover=function(){     if (rightmbclicked === true)     {     console.log(mysterydiv.id);     } } 

the problem is, can't figure out how 'mysterydiv', here function creates blocks (i need access them), , few important variables:

var blocknum = 0; var blockmax = 2500; var blocks = [];  function createblocks()     {     if (blocknum < blockmax)     {     blocknum += 1;     var block = document.createelement("div");     block.classname = "block";      block.id = "block" + blocknum;     blocks.push(blocknum);     block.style.width = block_width + "px";     block.style.height = block_height + "px";     block.style.cssfloat = "left";     //block.style.backgroundcolor = "#228b22";     block.style.backgroundimage="url('textures/grass.jpg')";     document.getelementbyid("container").appendchild(block,container.firstchild);     createblocks();     }     else     {     if (blocknum === blockmax)     {     createplayer();     paused = false;     }     }     } 

edit:

i'm trying id of block (mysterydiv) mouse cursor over.

i assume want handle event dynamically created blocks. please try ... hope want ... not sure rightmbclicked ... testing case set true

//after line block.style.backgroundimage="url('textures/grass.jpg')";   //here block.onmouseover = function(e){      if (rightmbclicked === true)     {         console.log(e);         console.log(this.id);     } };  //before line document.getelementbyid("container").appendchild(block,container.firstchild); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -