Jump to content

how to insert html taqs on javascript function


gongpex

Recommended Posts

Hello everyone, Please read my script :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  <head>	<title>append</title>  </head><script type="text/javascript">function addtext(what){if (document.createTextNode){var mytext=document.createTextNode(what)document.getElementById("mydiv").appendChild(mytext);}}</script><body><div id="mydiv" onClick="addtext('This Text was added to the DIV.' + '<br>')" style="font:20px bold; cursor:hand">Click here for example</div></body></html>

this script of course have function to add text "this text was added to DIV", But when I add html taqs <br /> it can't be run, How to add HTML taqs on javascript function, so that "<br />" taqs can be run on this javascript function? please someone answer me Thanks

Link to comment
Share on other sites

var lineBreak = document.createElement('br');

You could do that, or use the innerHTML property to append and parse text as HTML.

document.getElementById("mydiv").innerHTML += what;

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...