Embed HTML tag in JavaScript

I would like to embed the html tag in Javascript, between the script tag>

thanks

0


a source to share


6 answers


Is the E4X what you are looking for? This allows you to embed XML / XHTML into your JavaScript, for example:

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

      

I doubt what you need, but this is the only way to do what you ask. Also, I don't think it works in Internet Explorer. Eliminate this, it only works in Firefox.



If this is not what you want, use document.write()

as suggested by others.


Edit: E4X is now deprecated and has been removed from newer versions of Firefox. Don't use it. You have to use jQuery as it tells me below, or just create elements via document.createElement

and friends and inject them into the document.

+2


a source


Hey, maybe you are looking for jQuery.

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

      

See inline HTML tag.



Write less, do more

jQuery

+4


a source


You can not. If you want Javascript to write HTML you need to use document.write()

.

+2


a source


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

If you need to check if the document is ready or not, you can use JQuery

+1


a source


You cannot do this. tags can only contain text (usually javascript).

0


a source


document.write ('

color1: '+ color1 +'
color2: '+ color2 +'

');
0


a source







All Articles