albangt (16) [Avatar] Offline
#1
in collapsible.list.take.1.html; when I try to debug the codes using Companion,
I got a confusing result. the codes is as following:

$('li:has(ul)')
.click(function(event){
if (this == event.target) { //The target property sets or returns where to open the target URL.
console.log("collapsible.list.take.1.html event.target=%s",event.target);
console.log("collapsible.list.take.1.html $(this).children().is(:hidden)=%s",$(this).children().is(':hidden'));
if ($(this).children().is(':hidden')) {/*....}

The console will show the value of $(this).children().is(':hidden') is 0, and if things go this way, the if statement should not be executed, it is a little strange.

And furthermore, $('li:has(ul)').click(function(event){... should be performed only
when user click the list, but it be executed when the page onload. it really strange. thanks
mraj (104) [Avatar] Offline
#2
Re: a puzzled question about collapsible.list.take.1.html
Hi albangt,

At the top of p.132, the line of code labeled "6" is causing the click() event handler (defined at label "2") to fire/execute when the page loads. This is on purpose.

Since nothing is hidden initially (as you point out), the "else" statement of the click handler ends up getting executed, which adds the "plus" graphic and hides the children. The event handler is executed for every li which has a ul, so every collapsible list is collapsed when the page loads.
albangt (16) [Avatar] Offline
#3
Re: a puzzled question about collapsible.list.take.1.html
When I press +, the value of $(this).children().is(:hidden) inside if statement is 0;
and i found the return value of $(this).children().is(:hidden) is only -1 and 0.
And the command inside if statement shouldn't be execute if the value is -1 or 0.
I still can't figure it out. thanks.
albangt (16) [Avatar] Offline
#4
Re: a puzzled question about collapsible.list.take.1.html
I figure out, thanks.