dcsimg
www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23

Thread: innerHTML not working in xhtml 1.1?

  1. #16
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    Quote Originally Posted by michaellunsford
    Does anyone here have a link to a tutorial on the correct xhtml method for doing innerHTML rewrites?
    There are two alternatives.

    1. Serve the XHTML as HTML.
    2. Replace the unsupported innerHTML calls with createElementNS() calls.

    You cannot use innerHTML with XHTML as innerHTML is only supported for HTML pages and not for XHTML ones.


    There you are a complete tutorial on all the possibilities in a forum post so that no external link is needed.

  2. #17
    Join Date
    Mar 2005
    Posts
    767
    Quote Originally Posted by michaellunsford
    Does anyone here have a link to a tutorial on the correct xhtml method for doing innerHTML rewrites?
    Don't believe everything some dudes write on some web forum. From the HTML 5 draft:
    In an XML context, the document.write() method must raise an INVALID_ACCESS_ERR exception.

    On the other hand, however, the innerHTML attribute is indeed usable in an XML context.

  3. #18
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,774
    We're talking about XHTML 1.1 actually being served as application/xml+xhtml. The browser is parsing the XHTML document using the XML parser, and .innerHTML is an invalid attribute/DOM property in XHTML. While it may be valid in HTML 5.0, it is not valid and generates an error when the browser uses its XML parser. So yes, felgall is right.

  4. #19
    Join Date
    May 2005
    Location
    Dirty Jersey
    Posts
    1,402
    lolercats. great read so far.

  5. #20
    Join Date
    Apr 2006
    Location
    Houston
    Posts
    1,374
    Quote Originally Posted by michaellunsford
    Does anyone here have a link to a tutorial on the correct xhtml method for doing innerHTML rewrites?
    "Strict" XHTML deprecates Javascript methods like document.write() and write access to the .innerHTML property, because they can be used to insert invalid code that would break the document structure. (Nice, hey?)

    For example, if you could make a call like someDiv.innerHTML = '<p>look! invalid-ness!';, that would invalidate your document and break the page which has already rendered. To get around the lack of innerHTML however, DOM methods such as createElement() and createTextNode() do the trick. A bit more verbose, but valid under this XML-typed document.

    Here are some examples on how to create content using createElement and createTextNode:

    http://shapeshed.com/journal/learnin...ating_content/

  6. #21
    Join Date
    May 2007
    Location
    Cleveland, OH
    Posts
    1,403
    Step 1: Use HTML 4.01 Strict Doctype
    Step 2: ????
    Step 3: Profit

    XHTML is an unsupported standard, and serving it as HTML is in fact the same as serving invalid HTML. Unless your serving it as `application/xhtml+xml` , there is no need for it.

  7. #22
    Join Date
    Aug 2007
    Posts
    3,767
    Quote Originally Posted by slaughters
    To get around the lack of innerHTML however, DOM methods such as createElement() and createTextNode() do the trick. A bit more verbose, but valid under this XML-typed document.
    Well you have to use createElementNS() with application/xhtml+xml don't you?

  8. #23
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    You can't serve XHTML 1.1 as HTML, it has to be served as XHTML and so you must use createElementNS() to add elements to the page.

    You can serve XHTML 1.0 as HTML provided that you comply with the provisions in Appendix C. If you are going to selectively serve it as HTML or XHTML depending on whether the browser supports XHTML then you would need to test in the JavaScript for whether createElement or createElementNS is the appropriate call to use depending on which it is served as. If you are just going to serve it as HTML then it is effectively just slightly malformed version of HTML 4.01 that you are using.

    HTML supports both document.write (before the page finishes loading) and innerHTML neither of which are supported by XHTML.

    The HTML 5 standard is at least 10 years away from being implemented and so unless you are involved in the actual discussions on what it should include there is no reason for taking that version into consideration yet

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles