Here is a sample html file with a submit button. Now modify the style of the paragraph text through javascript code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset=utf-8 /> | |
<title>JS DOM paragraph style</title> | |
</head> | |
<body> | |
<p id ='text'>JavaScript Exercises - by Mr Khem Puthea</p> | |
<div> | |
<button id="jsStyle" | |
onclick="js_style()">Style</button> | |
</div> | |
</body> | |
</html> |
Here is the answer :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset=utf-8 /> | |
<title>JS DOM paragraph style</title> | |
</head> | |
<body> | |
<p id ='text'>JavaScript Exercises - by Mr Khem Puthea</p> | |
<div> | |
// use onclick action | |
<button id="jsStyle" onclick="jsStyle()"> | |
Style | |
</button> | |
</div> | |
<script> | |
function jsStyle() { | |
text.style.fontSize = "14pt"; // change font size | |
text.style.fontFamily = "Comic Sans MS"; // change font | |
text.style.color = "green"; // change color | |
} | |
</script> | |
</body> | |
</html> |
No comments:
Post a Comment