change the color of a php generated div using javascript -


i'm trying build small list users can indicate favorite theme.

so, basically, when user clicks on div background color (currently gray) changes color (green). when clicks time background color has change gray. able change color of divs, changed color of divs in front of him. indicated divs (green) should saved in database.

my php code:

<?php     while($keuzescherm= $allgenres->fetch_assoc())     {echo "<div class='keuzediv' id='".$keuzescherm['genrenaam'] ."'>" . $keuzescherm['genrenaam']."</>";} ?> 

i'm not sure javascript. i'm guessing need use getelementbyid(). @ moment i'm using this:

$(".keuzediv").on("click", function () {     $(this).toggleclass("green"); });  

and css:

.keuzediv {     background-color:#dddddd;      padding-top:5%;     color: black; } 

so question is: how can change background color of indicated div , save divs in database?

the problem php code. not correctly close each div.

change

{echo "<div class='keuzediv' id='".$keuzescherm['genrenaam'] ."'>" . $keuzescherm['genrenaam']."</>";} 

(which produces <div>...</>)

to

{echo "<div class='keuzediv' id='".$keuzescherm['genrenaam'] ."'>" . $keuzescherm['genrenaam']."</div>";} 

(which produces <div>...</div>)

you'll see fiddle there nothing wrong javascript.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -