in the change function,
var color = $(this).val();
should be
color = $(this).val();
as we use it as a global variable.
Posted 09 July 2011 - 01:37 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Loading Multiple classes</title>
</head>
<style type='text/css'>
09 #colorBox {
width:50px;
height:50px;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
<script type='text/javascript'>
$(document).ready(function(){
var color = '';
$('#blue').hide();
$('#red').hide();
$('#green').hide();
$('#TextGreen').hide();
$('#TextRed').hide();
$('#TextBlue').hide();
$('#colors').change(function(){
$('#' + color).hide();
$('#' + color + 'Text').hide();
color = $(this).val();
$('#' + color).show();
$('#' + color + 'text').show();
});
});
</script>
</head>
<body>
<select id='colors'>
<option value='blue' selected="selected">Blue</option>
<option value='green'>Green</option>
<option value='red'>Red</option>
</select>
<div id="ColourContainer" >
<div id='blue' class="blueClass"> THIS IS BLUEEE </div>
<!-- I want this to be displayed when the blue option is selected; hidden when other options chosen -->
<div id='red' class="RedClass" style="display:none;"> This is REEEED </div>
<!-- I want this to be displayed when the red option is selected, hidden when other options chosen -->
<div id='green' class="GreenClass" style="display:none;"> This is green'</div>
<!-- I want this to be displayed when the green option is selected, hidden when other options chosen -->
</div>
<div id="TextColourContainer">
<div id='TextBlue' class="blueClass">The Colour blue is a primay colour</div>
<!-- I want this to be displayed when the blue option is selected, hidden when other options selected -->
<div id='TextRed' class="redClass" style="display:none;">The Colour Red is also a primary colour</div>
<!-- I want this to be displayed when the red option is selected, hidden when other options selected -->
<div id='TextGreen' class="greenClass" style="display:none;">The Colour Green is another primary colour</div>
<!-- I want this to be displayed when the green option is selected, hidden when other options selected -->
</div>
</body>
</html>
