Hey everyone, I'm just starting to learn JavaScript. I'm working on a project where I want to change the color of all the divs in a container every time they are clicked.
For example, on the first click, I want all the divs to turn red. Then, on the second click, I want them to turn green!
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" type="text/css" rel="stylesheet">
<!--jquery easing plugin-->
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<!--custom css---->
<link href="css/phcoding.css" type="text/css" rel="stylesheet">
<title>cliciks</title>
<style>
</style>
</head>
<body>
<div id="container" onclick="myFunction();">
<div id="div1">This is div 1</p>
<div id="div2">This is div 2</p>
<div id="div3">This is div 3</p>
</div>
<script>
function myFunction(){
let x = document.getElementById("container");
y=x.children;
for(let i = 0; i< y.length;i++){
y[i].style.color="red";
y[i].style.color="green";
}
}
myFunction();
</script>
</body>
</html>