javascript - Div class background color change -


i trying change background color of div class = thisphotobox. should happen after pressing image inside of div. do wrong? , should add these onclick brackets? image:

  echo '<div class="thisphotobox">     <img src="'.$numphotos['link'].'" alt="photo" class="photolink" onclick="clicked()">     </div>'; 

and here goes function:

   function clicked(thisphotobox){      var div = document.getelementsbyclassname("thisphotobox");      elements.style.backgroundcolor="red";    } 

i'm thinking how make "checked" in checkbox.

1) instead of onclick="clicked()", write onclick=clicked();.

2) if there 1 div, should try give id, not class. can still use css modify if want to. and, of course, getelementsbyclassname becomes getelementbyid.

3) in clicked() create variable named div, try change background color of undeclared variable elements. change div, or change div elements.

+1 mean "checked checkbox" part? if want store clicked on image (and changed background color), can declare new variable (outside of clicked() function, can access elsewhere), false default, can change function this: variablename = true;. easiest method achieve it.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -