jquery accordion clicked header img change toggle
I have an accordion menu group made up of images. All the sections are closed at start, when one of the accordion sections is clicked/opened I want to change the image source of the just clicked header image and of course change it back later if the section is closed. How can I add this to the accordion? Thank you in advance.
The html and the jquery code开发者_JAVA百科:
$(document).ready(function () {
$("#accordion").accordion({
collapsible: true,
active: false,
header: '.head',
autoHeight: false,
});
});
<div id="accordion">
<div class="head"><a href="#"><img id="head1" src="images/Header1_closed.png" border="0" /></a></div>
<div><img src="images/accordPart3.png" /></div>
<div class="head"><a href="#"><img id="head2" src="images/Header2_closed.png" border="0" /></a></div>
<div><img src="images/accordPart5.png" /></div>
$('.head').click(function() {
var img = $(this).find('img');
var url = (img.attr('src')=='images/Header1_closed.png') ? 'images/Header1_open.png' : 'images/Header1_closed.png';
img.attr('src',url);
});
not sure if this is what your exactly looking from but here's a jQuery plugin I developed called Slidorion which combines and image slider and an accordian. Might be worth checking out:
http://www.slidorion.com
精彩评论