html - jQuery Toggle img inside a label -
i think have simple problem.
i trying create simple expand , collapse panel using .toggle.
although content expands , collapses expected, trying place icons user, cannot these images toggle too.
html:
<div class="toggle_head header"> <label> <img height="30px"; src="http://png-1.findicons.com/files/icons/2338/reflection/128/expand_alt.png" /> </label> <label class="hide"> <img height="30px"; src="http://png-2.findicons.com/files/icons/2338/reflection/128/collapse_alt.png" /> </label> <label>expand</label> </div> <div class="toggle_body"> <label>my content</label> </div>
jquery:
$(".toggle_body").hide(); $(".collapse").hide(); $(".toggle_head").click(function () { var $this = $(this); $this.next(".toggle_body").slidetoggle("slow", function () { $this.children('img').toggle(); }); });
css:
.header { background: #dadada; background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #dadada), color-stop(100%, #dadada)); background-image: -webkit-linear-gradient(#dadada, #dadada); background-image: -moz-linear-gradient(#dadada, #dadada); background-image: -o-linear-gradient(#dadada, #dadada); background-image: linear-gradient(#dadada, #dadada); color: #5c5c5c; height: 45px; } .hide { display: none; }
here's fiddle: http://jsfiddle.net/oampz/2zp9v/3/
any appreciated.
thanks
the img
not direct descendant of .toggle_head
, purpose use find
instead:
get descendants of each element in current set of matched elements, filtered selector, jquery object, or element.
code:
$(".toggle_body").hide(); $(".collapse").hide(); $(".toggle_head").click(function () { var $this = $(this); $this.next(".toggle_body").slidetoggle("slow", function () { $this.find('img').toggle(); }); });
Comments
Post a Comment