Totty.js
Totty.js

Reputation: 15841

How to store html into a javascript variable without parsing it, to be just like it is

Currently im doing like this but internet explorer 7 doesn't recognize it:

    gf.klass["LoginSkin"] = ""+<r><![CDATA[<div>
        <ul>
            <li value="login" >
                login
            </li>
            <li value="cancel">
                cancel
            </li>
        </ul>
    </div>]]></r>;;

Upvotes: 0

Views: 1273

Answers (2)

T.J. Crowder
T.J. Crowder

Reputation: 1074138

The syntax you've quoted is invalid JavaScript. The valid equivalent would be:

gf.klass["LoginSkin"] = '<div>\
    <ul>\
        <li value="login" >\
            login\
        </li>\
        <li value="cancel">\
            cancel\
        </li>\
    </ul>\
</div>';

Note the use of the trailing backslash to continue the literal to the next line. This is per Section 7.8.4 ("String Literals") of the spec.

Note that the leading characters of subsequent lines are part of the string (just as they are in your CDATA section).

Upvotes: 1

Ratna Dinakar
Ratna Dinakar

Reputation: 1573

you have element.innerHTML method to retrieve HTML of subelements !

Upvotes: 0

Related Questions