Note that there are some explanatory texts on larger screens.

plurals
  1. POI need help with DOM in javascript
    text
    copied!<p>I am suppose to Create a form that gives the user 3 different options to change the background color of the page. When the user clicks one of the options, the background color changes to match.And also create a div with some basic text to start out. Create a form that has a textarea. Use document.getElementById('yourelementid') to both find the value of the textarea and to change the basic text created in the div. (Hint: user innerHTML) Now I know how to do the form but i dont know how to get it to change the background when the user clicks that button.I am not really understanding how to use the innerHTML at all. If someone could explain or give me some website on how to understand this. Thank you.</p> <p>OK this is what I have so far and I am not still yet understanding it...</p> <pre><code> &lt;!DOCTYPE html PUBLIC "-//W3C//DTD Xhtml 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http:www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;title&gt;background-color&lt;/title&gt; &lt;meta http-equiv="content-type" content="text/html;charset=iso-8859-1" /&gt; &lt;script language="javascript" type="text/javascript"&gt; function changeBackgroundColor(objDivID) { var backColor = new String(); backColor = document.getElementById(objDivID).style.backgroundColor; if(backColor.toLowerCase()=='#A20000C') { document.getElementById(objDivID).style.backgroundColor = '#DF64BD'; } else { document.getElementById(objDivID).style.backgroundColor = '#FFDD73'; } } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;h3&gt;Change background color to:&lt;/h3&gt; &lt;div id="div1" style="background-color : #A2000C"&gt; &lt;p&gt;&lt;input type="radio" name="color" value="red" /&gt;Red&lt;br /&gt; &lt;input type="radio" name="color" value="pink" /&gt;Pink&lt;br /&gt; &lt;input type="radio" name="color" value="yellow" /&gt;Yellow&lt;br /&gt; &lt;/div&gt; &lt;input type="button" value="click here"onclick="changeBackgroundColor('div1')" /&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>i am still not sure why my box aint that big and is not chaning colors right i still have to have a box on there too. To ask to change the text of the color.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload