javascript - createTextNode in JS is not working in Chrome -
i trying out simple exercise, in want append
, generated javascript div id of "target-area". problem chrome refuses inject paragraph , gives me error: uncaught typeerror: object # has no method 'createtextnode'
here code:
<html> <head> <title>js</title> </head> <body> <div id="target-area"> <p id="tagline">hello world!</p> </div> </body> <script type="text/javascript"> // store target area variable keep things neat var targetarea = document.getelementbyid("target-area"); // create our <p> element var p = document.createelement("p"); // create text node inside <p>, note we're using variable "p" here var snippet = p.createtextnode("this generated paragraph"); // insert our generated paragraph dom targetarea.appendchild(snippet); </script> </html>
thanks!
document has createtextnode property , not element created
so code should this..
// store target area variable keep things neat var targetarea = document.getelementbyid("target-area"); // create our <p> element var p = document.createelement("p"); // create text node inside <p>, note we're // using variable "p" here var snippet = document.createtextnode("this generated paragraph"); // insert our generated paragraph dom p.appendchild(snippet); targetarea.appendchild(p);
Comments
Post a Comment