I have this chunk of jQuery that is doing strange behavior. When I load the page, my list is slided Up (completely folded) wich make sense. But I have to double click each parent to slide them down, which is not the normal behavior.
I think this line is the problem : $('#tree ul:parent').slideUp(); when I remove it, the sliding is working with a single click but the list does not come slided Up(completely forded) at the page load.
More strange, when a parent is double clicked, I can fold/unfold it with a single click after.
<script type="text/javascript" src="http://google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1");
google.setOnLoadCallback(function() {
$(function() {
$('#tree ul:parent').slideUp();
$("#tree li:parent").bind("collapse", function(evt) {
if(evt.target == evt.currentTarget)
{
$(evt.target).children().slideUp().end();
}
}).bind("expand", function(evt) {
if(evt.target == evt.currentTarget)
{
$(evt.target).children().slideDown().end();
}
}).toggle(function() {
$(this).trigger("collapse");
}, function() {
$(this).trigger("expand");
});
});
});
</script>
Here is the HTML code associated with that.
<ul id="tree">
<li>Sports
<ul>
<li>Football
<ul>
<li>logo</li>
<li>background</li>
</ul>
</li>
<li>Hockey
<ul>
<li>jquery</li>
<li>myscript</li>
</ul>
</li>
<li>Volley-Ball
<ul>
<li>jquery</li>
<li>myscript</li>
</ul>
</li>
<li>Badminton
<ul>
<li>page</li>
<li>typography</li>
</ul>
</li>
</ul>
</li>
<li>Travels
<ul>
<li>Africa
<ul>
<li>logo</li>
<li>background</li>
</ul>
</li>
<li>US
<ul>
<li>jquery</li>
<li>myscript</li>
</ul>
</li>
<li>Asia
<ul>
<li>jquery</li>
<li>myscript</li>
</ul>
</li>
<li>Europe
<ul>
<li>page</li>
<li>typography</li>
</ul>
</li>
</ul>
</li>
<li>Romans
<ul>
<li>Action
<ul>
<li>logo</li>
<li>background</li>
</ul>
</li>
<li>Love
<ul>
<li>jquery</li>
<li>myscript</li>
</ul>
</li>
<li>Adventure
<ul>
<li>jquery</li>
<li>myscript</li>
</ul>
</li>
<li>Test
<ul>
<li>page</li>
<li>typography</li>
</ul>
</li>
</ul>
</li>
<li>Tst
<ul>
<li>Jouets
<ul>
<li>logo</li>
<li>background</li>
</ul>
</li>
<li>Activities
<ul>
<li>jquery</li>
<li>myscript</li>
</ul>
</li>
<li>jsccc
<ul>
<li>jquery</li>
<li>myscript</li>
</ul>
</li>
<li>cssss
<ul>
<li>page</li>
<li>typography</li>
</ul>
</li>
</ul>
</li>
</ul>