So I’m new to jQuery, and I can’t figure out why my IF statement isn’t working, although code works when I comment out the IF. Please help me…Thanks!
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("tr.anon").hide();
$("#hideID").change(function(){
// IF ($("#hideID option[value='no']").text()){
$("tr.anon").show();
// alert($this).find("option:selected").text()+' clicked!');
// }ELSE{
// $("tr.anon").hide();
// }
});
});
</script>
</head>
<body>
<p>Would you like to remain anonymous? <select id="hideID">
<option value="yes">Yes</option>
<option value="no">No</option>
</select></p>
<table border="1px">
<tr class="anon">
<td>Enter your name:</td>
<td><input class="field2" type="text" /></td>
</tr>
</table>
</body>
</html>
Thanks for the quick feedback… I have adjusted my code to the following but it still is not working.
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script><script type="text/javascript">
$(document).ready(function(){
$("tr.anon").hide();
$("#hideID").change(function(){
// if ($("#hideID option[value='no']").text()){
$("tr.anon").show();
// alert(#hideID).find("option:selected").text()+' clicked!');
// }else{
// $("tr.anon").hide();
// }
});
});
</script>
</head>
<body>
<p>Would you like to remain anonymous?
<select id="hideID">
<option value="yes">Yes</option>
<option value="no">No</option>
</select></p>
<table border="1px">
<tr class="anon">
<td>Enter your name:</td>
<td><input class="field2" type="text" /></td>
</tr>
</table>
</body>
</html>
Change to value===’no’. = is for assignment, and == and === are comparison.