Skip to content
Snippets Groups Projects
Commit a75fa50d authored by Minhao Qiu's avatar Minhao Qiu
Browse files

udpate

parent e1b59625
No related branches found
No related tags found
No related merge requests found
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Color test</title>
<script>
// use arrow funtion
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('.color-change').forEach(button => {
button.onclick = () => {
alert(button.dataset.color)
document.querySelector('#hello').style.color = button.dataset.color
}
})
})
</script>
</head>
<body>
<h1 id="hello">Hello</h1>
<button class="color-change" data-color="red">Red</button>
<button class="color-change" data-color="blue">Blue</button>
<button class="color-change" data-color="green">Green</button>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Color test3</title>
<script>
document.addEventListener('DOMContentLoaded', () => {
document.querySelector('#color-change').onchange = function() {
alert(this.value)
document.querySelector("#hello").style.color = this.value;
}
});
</script>
</head>
<body>
<h1 id="hello">Hello</h1>
<select id="color-change">
<option value="black">Black</option>
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
</select>
</body>
</html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment