html - Javascript checkbox toggle div hide show -
i looking have checkbox (football) when
unchecked:
- displays 1 div (footballchoice) containing label image checkbox changes mouseover
checked:
- hides div (footballchoice)
- shows hidden div (footballchecked) contains alternate label image
- shows hidden div (footballteams).
when unchecked again, needs return it's original state.
alternatively if knows how change label image when checked same 1 specified in mouseover element here, usefull altetrnative?
thank in advance.
<script type="text/javascript" src="http://code.jquery.com/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('input[type="checkbox"]').click(function(){ if($(this).attr("value")=="footballteams"){ $(".footballteams").toggle(); $(".footballchecked").toggle(); $(".footballchoice").toggle(); } }); }); </script>
.footballchecked { display: none; } .footballchoice { display: show; } .sport { display: none; border: 1px dashed #ff3333; margin: 10px; padding: 10px; background: #003366; }
<input id="football" type="checkbox" value="footballteams"> <div class="footballchoice"> <label for="football" class="footballchoice"> <img src="http://web.static.nowtv.com/email-marketing/assets/structure/sportspref_football_100x130.png" onmouseover="this.src='http://web.static.nowtv.com/email-marketing/assets/structure/sportspref_football_name_100x130.png';" onmouseout="this.src='http://web.static.nowtv.com/email-marketing/assets/structure/sportspref_football_100x130.png';" alt="football" title="football"> </label> </div> <div class="footballchecked"> <label for="football"> <img src="http://web.static.nowtv.com/email-marketing/assets/structure/sportspref_football_name_100x130.png" alt="football" title="football"> </label> </div> <div class="sport footballteams"> football teams here </div>
do have use javascript? use css pseudo-selector :checked
, general siblings selector display elements based on whether checkbox
:checked
or not.
e.g:
#football {opacity:0.2;} .checked {display:none;} #football:checked ~ .unchecked {display:none;} #football:checked ~ .checked {display:block;} label { display:inline-block; border:1px solid blue; padding:20px; background:url(http://lorempixel.com/100/100/sports) } label:hover { border-color:red; background:url(http://lorempixel.com/100/100/cats) } div {border:1px dotted green;}
<input id="football" type="checkbox" value="1" /> <div class="unchecked"> unchecked: displays 1 div <div id="footballchoice"> (footballchoice) containing <label for="football">label image checkbox changes mouseover</label> </div> </div> <div class="checked"> checked: hides div (footballchoice) shows hidden div <div id="footballchecked"> (footballchecked) contains <label for="football">alternate label image</label> </div> shows hidden div . <div id="footballteams"> (footballteams) </div> when unchecked again, needs return it's original state. </div>
Comments
Post a Comment