jquery - Javascript change multiple element style on click -


consider following images, lets user guess win sports match

enter image description here

enter image description here

im trying following:

  • change style (text color) of selected teams black, inorder user see selected before pressing submit

    while($fixtures> $upcoming){  //radio buttons select team <input type="radio" id="'.$x.'"onclick="teams()" name="picks['.$x.']" value="'.$row['team1'].'"/>  <input type="radio" onclick="teams()" name="picks['.$x.']" value="'.$row['team2'].'"/> <input type="radio" onclick="teams()" name="picks['.$x.']" value="draw" />     echo'<b>by</b>';         echo'<select name="score[]" id="score[]">';             echo'<option value="0">0</option>';             echo'<option value="1">1</option>';             echo'<option value="2">2</option>';             echo'<option value="3">3</option>';             echo'<option value="4">4</option>';             echo'<option value="5">5</option>';              echo'</select>';                 echo'<b>points</b>';    echo' </div>  // team names displayed, needs change style onclick echo'<div id="disppicks">';     foreach($dispteam1 $key => $team1){         echo '<p class="team1">';         echo $team1;         echo'</p>';         echo ' vs ' ;         echo'<p class="team2">';         echo $dispteam2[$key];         echo'</p>';     } echo'</div>'; 

    i tried write following javascript

      var elements = document.getelementbyid("makepicks").elements;     var len = elements.length;     var team=[]     for(x=0; x<len; x++){       if(elements[x].type == "radio" && elements[x].checked== true)       {         team[x] = t1[x].value; //the value of team[x] selected team        } 

my problem

team[x] has selected team im stuck...and cant figure out how change team names style...from here.

things consider:

  • the teams/fixtures dynamically pulled database , generated in php loop
    • every round have different number of fixtures

so should doing this. add same class clickable teams, class="team". in css add this

.selected{    background-color:#fff; } 

now using jquery this,

$('.team').click(function(){    $(this).toggleclass('selected'); }) 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -