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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post

    HTML in JS wont validate

    the HTML validator wont validate this:

    document.getElementById('newsDisplayClassic').innerHTML = '<img src="http://www.foo.com/img/icons/icon_newsDisplayCheckmark.png" width="32" height="26" alt="" />';

    how do I write it so it is valid?

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Bobafart View Post
    the HTML validator wont validate this:

    document.getElementById('newsDisplayClassic').innerHTML = '<img src="http://www.foo.com/img/icons/icon_newsDisplayCheckmark.png" width="32" height="26" alt="" />';

    how do I write it so it is valid?
    you must use CDATA section in xhtml strict to insert chars as <, & , >
    as in this example:

    Code:
    <script type="text/javascript">
    // <![CDATA[
    your js code
    // ]]>
    </script>
    also you can use the html comments instead, <!--, -->

    best regards

  • Users who have thanked oesxyl for this post:

    Bobafart (02-28-2008)


  •  

    Posting Permissions

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