I am new to jQuery. I am trying to display or hide a span based on the selection of a checkbox. Here’s my code:
<script type = "text/javascript">
$('#chkShowDescriptions').change(function () {
var display = this.checked ? 'block' : 'none';
$('.desc').css('display', display);
}
);
</script>
<p>
<input type = "checkbox" id = "chkShowDescriptions"
name = "chkShowDescriptions" />Show Descriptions
</p>
@if(@item.Description != null)
{
<span class = "desc" style =
"font-size: 0.7em; color: Gray; text-align:
justify; display: none;">
Description: @item.Description<br />
</span>
}
However, I get a run-time exception that says: Microsoft JScript runtime error: Object expected
I am using IE 8 on Windows 7.
I found the cause of the error. Or so I think.
I think I put the script tag declaration before including the jQuery library declaration/include.