Re: Dynamically building objects
RobG wrote:[color=blue]
> Richard Cornford wrote:[/color]
<snip>[color=blue][color=green]
>> As functions assigned to event handling properties ...[/color][/color]
<snip>[color=blue]
> In other words...
>
> function sayHi() {
> alert( ( this.id )? this.id : 'I have no ID' );
> }
>
> ...
> var a = document.create Element('A');
> a.onclick = sayHi;
> ...
>
> will suffice. Thanks.[/color]
Yes. But there is still the question of what the ID is going to be used
for. It is a bit depressing to recall the number of times I have seen
people reading - this.id - and then using the ID to look up a reference
to the element with - document.getele mentById -, without ever seeing
that - this - was (and must be) the value they wanted in the first
place.
Richard.
RobG wrote:[color=blue]
> Richard Cornford wrote:[/color]
<snip>[color=blue][color=green]
>> As functions assigned to event handling properties ...[/color][/color]
<snip>[color=blue]
> In other words...
>
> function sayHi() {
> alert( ( this.id )? this.id : 'I have no ID' );
> }
>
> ...
> var a = document.create Element('A');
> a.onclick = sayHi;
> ...
>
> will suffice. Thanks.[/color]
Yes. But there is still the question of what the ID is going to be used
for. It is a bit depressing to recall the number of times I have seen
people reading - this.id - and then using the ID to look up a reference
to the element with - document.getele mentById -, without ever seeing
that - this - was (and must be) the value they wanted in the first
place.
Richard.
Comment