tags:

views:

1200

answers:

6

I'd like to embed an html tag in Javascript, between the script> tag

Thanks

A: 

You can't do that. tags can contain just text (usually javascript).

Eduardo Scoz
+2  A: 

You can't. If you want the Javascript to write HTML, you'll have to use document.write().

Chuck
A: 

document.write('

colour1: ' + colour1 + '
colour2: ' + colour2 + '

');

Searock
+2  A: 

Is E4X what you're looking for? It allows you to embed XML/XHTML within your JavaScript, like this:

var someXml = <div><b>Some Text</b></div>;

I doubt that's what you need, but that's the only way you can do what you're asking. Also, I don't think it works in Internet Explorer. Scratch that, it only works in Firefox.

If that's not what you want, use document.write(), as suggested by others.

musicfreak
+1  A: 

Hey maybe you're looking for jQuery.

$("p").text("<b>Some</b> new text.");

See embedded HTML tag.

Write Less, Do More

jQuery

rymn
+1  A: 

If you write this inside your body tag then also you can access this using your javascript.

If yo want to check whether the document is ready or not then you can use JQuery

rahul