SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    createElement vs createElementNS

    Curiosity strikes again.

    I know you're supposed to use createElementNS when using XHTML. However, assuming you've done things properly and put the xmlns attribute in <html>, why should you need to use createElementNS instead of createElement? If I create the element and then attach it so something that's a child of <html>, then surely it's obvious what namespace it's in?

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can have more than 1 xmlns attribute - in xml at least.

  3. #3
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    True... I suppose I should have been more specific. If you only have xmlns="http://www.w3.org/1999/xhtml" in , should you still use createElementNS or would createElement be all right? I know this would defeat the purpose of using XHTML since you might as well use HTML 4.01, but would just using createElement theoretically be OK?

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Only use createElementNS (et al) if your xml uses more than one namespace, otherwise it will perform the same function as createElement.

  5. #5
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Apparently createElement (and innerHTML) fails in older versions of Mozilla if the page is served as XHTML. Anyway, you've answered my question. Cheers.

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,813
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    createElement assumes that there are no such thing as namespaces and so when you have one or more namespaces you must use createElementNS
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

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