Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2003
    Location
    china
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    which is more efficient?

    I defined id for my cell element, now I want to refer them by id,
    can someone tell which of the following way is most efficient?

    1. Define same Id for a group of cells, and use document.all(id) to get a reference array of them.
    2.Define unique Id for each cell element, and use document.getElementById(id) to access them.
    3.Define unique Id for each cell element, and use eval(id) to manipulate them.

    by the way, when I want to convert some number to float,
    number=parseFloat(number) or number=new Number(number) ,
    which will be executed faster?

    My javascript program is running under IE6.0.

    I appriciate for any suggestion, thank you.
    Last edited by yao_jw; 12-24-2003 at 04:20 AM.

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, #1 is completely invalid code. Even though it works in IE, it's not in the soec, and isn't even remotely cross-browser.

    For #3, eval() can be slow, and is often times unreliable.

    I'd say that #3 is the best choice.

    As far as parsing, I'm not entirely sure which is faster, but if I had to guess, I'd say new Number().

  • #3
    New Coder
    Join Date
    Nov 2003
    Location
    china
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, but what is soec? and as to document.all(), if I suppose
    my program will work only under IE, are there still problems with it? I need to decide if I have to revise my previous code using that function.

  • #4
    Regular Coder
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I meant "spec", as in Specification.

    And even if you're only using IE6, why not still write valid code? It would make it cross-platform anyways. I just have a problem with writing bad code when you don't have to.

    Instead of using document.all.elementID, use document.getElementById(elementId). It's proper, valid, and still works perfectly fine in IE6.

    document.all is unnecessarily proprietary, it's not valid DOM, and there's really no reason to use it. Besides, all you're doing is promoting Microsoft-only technology. Technology that is fairly stagnant, at least in the web world...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •