Click Next Javascript Base (ok)

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style type="text/css" media="screen">
  	#header {
  		background-color: #00ff;
  		color: #fff;
  		width: 100px;
  		height: 30px;
  		line-height: 30px;
  		text-align: center;
  	}
  	.mystyle {
  		background-color: #f00;
  		color: #fff;
  		font-weight: 700;
  	}
  </style>
</head>
<body>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <script src="https://code.jquery.com/jquery.js"></script>
  <div id="header">CLICK ME</div>
  <div id="alo">
  	<p class="example mystyle">A heading with class="example"</p>
    <p class="example">A paragraph with class="example".</p>
    <p class="example">A heading with class="example"</p>
    <p class="example">A paragraph with class="example".</p>
  </div>
    <script>
    var x = document.querySelectorAll(".example");
    var y = document.getElementsByClassName("example");
    var i = 0;
    function nextItem() {
      i = i+1;
      i = i % x.length;
      if(document.querySelector('.mystyle') !== null) {
      	var j;
				for (j = 0; j < y.length; j++) {
				  y[j].classList.remove("mystyle");
				}
      }
      return x[i].classList.add("mystyle");
    }
    document.getElementById('header').addEventListener('click', function(e) {
      nextItem();
    });
    </script>
</body>
</html>

Last updated