Example
Learn the test-driven development approach when building apps
<!DOCTYPE html>
<html>
<head>
<title>Change Color</title>
</head>
<body>
<button id="changeGreen">Change Font Color Green</button>
<button id="changeRed">Change Font Color Red</button>
<p>
<span id="output">Learn the test-driven development approach when building apps</span>
</p>
<script>
document.getElementById("changeGreen").onclick = function(){
document.getElementById("output").style.color = 'green';
}
document.getElementById("changeRed").onclick = function(){
document.getElementById("output").style.color = 'red';
}
</script>
</body>
</html> Most Helpful This Week
How to change the height of Textarea on click?
jQuery check if an element is visible or hidden
Get largest number from each sub-arrays
How to check if an element or HTML tag exists using JavaScript?
jQuery get the coordinates of div clicked
JavaScript convert string variable in boolean using Regex
How to show hide option list items using jQuery?
How to declare and print value of variable in JavaScript?
Check if a string ends with the given target string
How to current URL, HOST and URL attributes using JavaScript or jQuery?