<html>
<head>
<style type="text/css">
.step_box {
border: 1.0px solid rgb(204, 204, 204);
border-radius: 10.0px 10.0px 10.0px 10.0px;
}
.step_box:hover{
background: rgb(184, 225, 252);
}
.selected {
background-color : #fff000;
}
</style>
<script src="http://code.jquery.com/jquery-1.7.2.js"></script>
<script type="text/javascript">
$('.step_wrapper').on('click','.step_box',function () {
$('.step_box').removeClass('selected');
$(this).addClass('selected')
});
</script>
</head>
<body>
<div class="step_wrapper">
<div class="step_box" onclick="show('Page1');"> <span>Content of page 1</span></div>
<div class="step_box" onclick="show('Page2');"> <span>Content of page 2</span></div>
<div class="step_box" onclick="show('Page3');"> <span>Content of page 3</span></div>
</div>
</body>
</html>
At the moment, there are three child divs within a parent div. The step_box divs currently have a background color on hover. However, after clicking using the onclick method, I would like the step_box div to retain the background color with the ".selected" style. This will help highlight the div that the user selected.
Any suggestions on how to achieve this?
The code appears to work on this fiddle, but it doesn't function properly when loaded in my browser. Could it be an issue with how I linked jQuery to the HTML document?
If there are alternative methods or suggestions for accomplishing this task, I am open to hearing them. Thank you!