Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Matthew Smart
12,567 PointsJquery: Change table row when select option is changed??
when the select option is 1 i want the table row to be blue,
if its 2 then red and if its 3 then yellow. This is my code so far.
<style> table td,th{ border:1px solid black; padding-left:100px; } table tr{ background-color:grey; } } .on{ background-color:blue; } </style>
<body> <table id="table"> <tr> <th> Hello </th>
<th>
Is it
</th>
</tr>
<tr id="options">
<td>
yayaya
</td>
<td>
<select id="select">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</td>
</tr>
</table>
</body>
<script>
$('select').change(function(){
if($('select').text() == "1"){
$('#options').addClass('on');
}
}):
<script>
This isnt working, any ideas?
2 Answers
Hugo Paz
15,622 Points$('select').change(function(){ if($('select').val() == "1"){ $('#options').addClass('on'); } });
You also have an extra } in your css
Matthew Smart
12,567 Pointsi was so close :( aha but thanks for that.
I should have looked into it a bit more, but ive been coding all day and getting to the time of the day where its all a blur :)