Onclick event in nested list

J

Jorge

e = e || window.event;

Does that look like a DOM node to you?

Ooops, of course not, I thought I had posted this version:

<script>
window.onload= function () {

document.getElementById('sublist').onclick= function (e) {
e= (e= e || window.event).target || e.srcElement;
if (e === this) {
this.style.border= this.style.border ? "" : "1px solid red";
}
e= null;
};

};
</script>

Note the lines:
e= (e= e || window.event).target || e.srcElement;
if (e === this) {

that later on I rewrote as:
if (((e= e || window.event).target || e.srcElement) === this) {

....but forgot to remove the e= null;

So, given
e= (e= e || window.event).target || e.srcElement;

should I have nulled var e before returning ?
 
D

David Mark

Ooops, of course not, I thought I had posted this version:

<script>
window.onload= function () {

  document.getElementById('sublist').onclick= function (e) {
    e= (e= e || window.event).target || e.srcElement;
    if (e === this) {
      this.style.border= this.style.border ? "" : "1px solid red";
    }
    e= null;
  };

};

I'm glad you didn't.
</script>

Note the lines:
e= (e= e || window.event).target || e.srcElement;

I saw it.
if (e === this) {

that later on I rewrote as:
if (((e= e || window.event).target || e.srcElement) === this) {

...but forgot to remove the e= null;

Regardless, you don't need it.
So, given
e= (e= e || window.event).target || e.srcElement;

should I have nulled var e before returning ?

No. Re-read the article on closures.
 
J

Jorge

(...)

I think that is complete bullshit.
(...)

(OMG), how can you say that :)

"The IE team has been working hard to solve the problem"

....when the patch has taken them almost 8 years ("working hard") ?
 
D

David Mark

(OMG), how can you say that :)

"The IE team has been working hard to solve the problem"

...when the patch has taken them almost 8 years ("working hard") ?

And the jQuery team has been "working hard" to solve IE6 for half of
that time. Is it just me or is such futility surreal (and doomed to
fail?) IE6 still leaks, jQuery still throws exceptions in *and* leaks
like a sieve in IE6 (among other problems.) AIUI, one of the reasons
their latest patchwork quilt ripped is the "live" event nonsense.
Great idea throwing that in when they still can't figure out
attributes, properties, ActiveX, etc. Been almost two years since I
gave John Resig all of those answers on a plate. Or perhaps I'm just
being "rude?" LOL.
 
J

Jorge

(...)
One should be able to click Page 4 without collapsing the second level
tree.

(...)
<script type="text/javascript">
function toggleDisplay(that, what)
{
var eStyle;
if (that === (event.target || event.srcElement)) {
eStyle= document.getElementById(what).style;
eStyle.display = eStyle.display != 'none' ? 'none' : 'block';
}
}
</script>
(...)
<li id="secondlevel" onclick="toggleDisplay(this,
'secondlevel_content');">
(...)
 
T

Thomas 'PointedEars' Lahn

André Hänsel said:
Uh, guys, I'm pretty sure that the issue is not that complicated and
must have been done a thousend times before. [...]

Maybe you should read everything that has been replied?


PointedEars
 
A

André Hänsel

Uh, guys, I'm pretty sure that the issue is not that complicated and
must have been done a thousend times before. [...]

Maybe you should read everything that has been replied?

I did and I didn't want to offend anyone who contributed. I just got
the impression that I gave too little context and I wanted to make
clear that I didn't have a very special problem but rather wanted a
simple collapsible tree.
 
J

Jorge

I did and I didn't want to offend anyone who contributed. I just got
the impression that I gave too little context and I wanted to make
clear that I didn't have a very special problem but rather wanted a
simple collapsible tree.

A true collapser:

(...)
<li id="secondlevel" onclick="this.parentNode.innerHTML='';">
(...)
 
T

Thomas 'PointedEars' Lahn

André Hänsel said:
Thomas said:
André Hänsel said:
I have set an event handler on the "sublist" LI that toggles the
visibility of the contained UL.
Where?
Uh, guys, I'm pretty sure that the issue is not that complicated and
must have been done a thousend times before. [...]
Maybe you should read everything that has been replied?

I did and I didn't want to offend anyone who contributed. I just got
the impression that I gave too little context and I wanted to make
clear that I didn't have a very special problem but rather wanted a
simple collapsible tree.

Well, you have been presented with possible solutions (in particular, one by
me). If it were more simple, you would have written it by yourself by now,
wouldn't you? Script-kiddie support is next door.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top