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 9 of 9
  1. #1
    Regular Coder
    Join Date
    Jan 2004
    Location
    USA
    Posts
    364
    Thanks
    12
    Thanked 6 Times in 6 Posts

    Different syntaxes

    Hi,
    I've seen two different types of syntaxes when it comes to modifiying elements.

    Syntax #1:
    Code:
    var element = document.createElement('div');
    	element.setAttribute('id', 'menu');
    Syntax #2:
    Code:
    var element = document.createElement('div');
    	element.id = 'menu';
    What's the difference? And what are they called?

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    The first one is using the DOM2 setAttribute method while the second one is using the method that existed before the DOM standard was created (usually referred to as DOM0). Not all browsers support setting all attributes via the setAttribute method yet.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Regular Coder
    Join Date
    Jan 2004
    Location
    USA
    Posts
    364
    Thanks
    12
    Thanked 6 Times in 6 Posts
    So the second one is more widely supported? And are there any differences speed-wise? What are the pros and cons of each?

    Thanks.

  • #4
    Senior Coder
    Join Date
    Feb 2006
    Location
    USA
    Posts
    1,013
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Using the first method you can run into several bugs, especially in IE.

    I can't think of any cons to using the DOM0 method.
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
    Java != JavaScript && JScript != JavaScript
    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

  • #5
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    pop-up menu for ads

    hi everyone.. i am new here and i know you can help me with my problem.

    i am thinking of a site where visitors could only enter my main page if they will click the support button which that support button would link to an ad.

    can you suggest of a code?

    thank you.

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    verginette, please, don't cross-post. You have already:
    http://www.codingforums.com/showthread.php?t=92372

    Furthermore, this post here has nothing to do with this thread here.
    Last edited by Kor; 07-31-2006 at 02:22 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #7
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    It's not just a DOM0-method - many of those were standardized as part of DOM2 HTML.

  • #8
    Regular Coder
    Join Date
    Jan 2004
    Location
    USA
    Posts
    364
    Thanks
    12
    Thanked 6 Times in 6 Posts
    How can I get DOM0 to work with attributes like tabindex?

    Code:
    element.tabindex = '1';
    doesn't work.

  • #9
    Senior Coder
    Join Date
    Feb 2006
    Location
    USA
    Posts
    1,013
    Thanks
    0
    Thanked 0 Times in 0 Posts
    JavaScript is case-sensitive.

    The property is tabIndex, not tabindex.

    http://www.w3.org/TR/DOM-Level-2-HTML/html.html
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
    Java != JavaScript && JScript != JavaScript
    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.


  •  

    Posting Permissions

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