Jump to content

User:Amit6/sandbox14.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js" ></script>
<script type="text/javascript">
$(document).ready(function(){

//Store Image paths
var toggleMinus = 'path/to/minus/image';
var togglePlus = 'path/to/plus/image';

var $subHead = $('.children').parent();

//Add the Plus image to every child by default
$subHead.prepend('<img src="' + togglePlus + '" alt="collapse this section" /> ');

//By Default put the Menu in collapsed state
$('.children').parent().children('ul').slideUp('fast');

//Expand All Code
$('.expand').click(function() {
		$subHead.children('ul').slideDown('fast');
		$('img', $subHead).attr('src', toggleMinus);
});

//Contract All Code
$('.contract').click(function() {
		$subHead.attr('src', toggleMinus).children('ul').slideUp('fast');
		$('img', $subHead).attr('src', togglePlus);
});

//Expand or Contract one particular Nested ul
$('img', $subHead).addClass('clickable').click(function() {
var toggleSrc = $(this).attr('src');
if ( toggleSrc == toggleMinus ) {
$(this).attr('src', togglePlus).parent().children('ul').slideUp('fast');
} else{
$(this).attr('src', toggleMinus).parent().children('ul').slideDown('fast');
};
});
});
</script>