the checkboxes are checked by default. if unchecked they should hide the text. how do i hide or show the text in jquery?
html:
<div class="check">
<p><input type="checkbox" value="Name" id="name" checked /> <label for="name">Name</label></p>
<p><input type="checkbox" value="Reference " id="reference" checked /> <label for="reference">Reference</label></p>
</div>
<div id="nametxt"> Show Name TEXT </div>
<div id="reftxt"> Show Ref TEXT </div>
Change the id of
<div id="reftxt">to<div id="referencetxt">and then you can do this:The change event will fire if its clicked on or if someone uses the keyboard to check/uncheck the checkbox.
As long as the
ID‘s of the text divs are alwayscheckbox ID + 'txt'and are indiv.checkthen this will handle those too. Keeps you from having to repeat yourself as you get more checkboxes.