SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Dec 2005
    Location
    Australia
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question a better way to hold a large amount of HTML in a JS variable?

    Hi,
    I have a javascript function that needs to insert a large block of HTML code into a DIV. The problem is that surrounding this HTML code with quotes to assign it into a javascript variable requires a lot of slashes and makes it less readable.

    Is there a better way to hold HTML code in a javascript variable? Like maybe:
    PHP Code:
    var innerHTML "
    <![CDATA[
    <table border="
    0">...</table>
    ]]>
    "

    or something?

    I would appreciate your feedback. Thanks!

  2. #2
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't substitute an XML CDATA section for a JavaScript string. What you could do is put the table in a hidden DIV and retrieve it with the DIV's innerHTML attribute.


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
  •