Question

create a web page with a textbox labelled "color", and several; h1's. when the user clicks...

create a web page with a textbox labelled "color", and several; h1's. when the user clicks on any h1 change the color of the h1 that was clicked to color that is typed in the textbox using javascript.. please help me out

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code

<!DOCTYPE html>
<html>
<head>
   <title>Color Label</title>
</head>

<body>
Label : <input type="text" id="Label"> <!-- Text Label-->
<div id="1"><h1>First Heading</h1></div> <!-- Headings -->
<div id="2"><h1 >Second Heading</h1></div>
<div id="3"><h1>Third Heading</h1></div> <!-- We assign ids to each element -->
<div id="4"><h1>Fourth Heading</h1></div>
<div id="5"><h1>Fith Heading</h1></div>

</body>

<script type="text/javascript">

   document.getElementById('1').onclick = changeColor1; // adding on click event to each elmenet and calling respective functions
   document.getElementById('2').onclick = changeColor2;   
   document.getElementById('3').onclick = changeColor3;   
   document.getElementById('4').onclick = changeColor4;   
   document.getElementById('5').onclick = changeColor5;   

function changeColor1() {
document.getElementById('1').style.color = document.getElementById("Label").value; // change color for id 1to what is entered in text box
return false;
}


function changeColor2() {
document.getElementById('2').style.color = document.getElementById("Label").value; // similarly change value for other h1's
return false;
}


function changeColor3() {
document.getElementById('3').style.color = document.getElementById("Label").value;
return false;
}


function changeColor4() {
document.getElementById('4').style.color = document.getElementById("Label").value;
return false;
}


function changeColor5() {
document.getElementById('5').style.color = document.getElementById("Label").value;
return false;
}   


</script>

</html>

Output

Label: purple First Heading Second Heading Third Heading Fourth Heading Fith HeadingLabel: green First Heading Second Heading Third Heading Fourth Heading Fith Heading

Add a comment
Know the answer?
Add Answer to:
create a web page with a textbox labelled "color", and several; h1's. when the user clicks...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT