Dynamically building objects

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richard Cornford

    #16
    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.


    Comment

    • sirsean@gmail.com

      #17
      Re: Dynamically building objects

      Actually that question is now moot. I only needed to be able to get the
      id because I needed the number in it. Rob's post helped tremendously,
      and now I can use the DOM onclick property (who would have thought
      wrapping it in function(){} would have done the trick?). Therefore, the
      id isn't needed any more and everything is working swimmingly.

      Thanks for the help, all.
      SEAN

      Comment

      Working...