Jump to content

button to write


mwbarry

Recommended Posts

I'm just learning javascript and I'm having trouble with something I would have thought to be simple. I want to create a button that, when clicked, makes a string of text appear. Every time I press the button the page just goes blank. I am trying to do this based on the code given in the 'home' section of the javascript tutorial. I keep seeing the 'innerHTML' code in javascript functions. What does this do?

<html><head><script type="text/javascript">function write() {	document.getElementById("space").innerHTML=Hello World!;	}</script></head><body><button type="button" onclick="write()">write stuff</button><div id="space"></div></body></html>

Link to comment
Share on other sites

For some reason, I have a feeling that "write" is calling the predefined write() method of the document object. You should give your function a diferent name. Aside from that, you have to put quotation marks around your strings.The innerHTML property of the HTMLElement object returns a string containing the HTML within the element, or sets the HTML to be used inside the element.http://www.w3schools.com/jsref/prop_html_innerhtml.asp

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...