www.webdeveloper.com
Results 1 to 4 of 4

Thread: JavaScript xhtml validation

  1. #1
    Join Date
    Apr 2005
    Posts
    88

    JavaScript xhtml validation

    Hi, i am trying to validate some page with xhtml validator, for the following part i got errors.
    Anyone knows what does it want?

    HTML Code:
    <script type="text/javascript">
      document.getElementById('myImage').innerHTML = (document.all ? '' : "&nbsp;&nbsp;&nbsp;&nbsp;<img src='image.gif' alt='' />");
    </script>
    Error: "document type does not allow element "img" here", and it points to the closing part of the mg tag ('>'). now when try to replace < with &lt; and > with &gt; validator is fine with that, but then the browser (firefox) shows the actual text and not the image....

    any help plz?

  2. #2
    Join Date
    Nov 2002
    Location
    Dartmoor [Holiday]
    Posts
    2,382
    You need to wrap the code in a CDATA section.

    Adam

  3. #3
    Join Date
    Apr 2005
    Posts
    88
    tnx, that convinced the validator

    should i put some header about xml in the page ?

    I am getting syntax error in java script console for the <![CDATA[ .....
    Last edited by TrolloC; 04-16-2005 at 06:49 AM.

  4. #4
    Join Date
    Nov 2002
    Location
    Dartmoor [Holiday]
    Posts
    2,382
    Sorry, I should have mentioned that you'll need to comment out the CDATA section as well. Fortunately, the JS comment characters aren't XML special characters, so you can do this:

    Code:
    <script type="text/javascript">
    /*<![CDATA[*/
    ...
    /*]]>*/
    </script>
    Adam

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