jQuery addClass example

Change class name on click in jQuery

by jklee

HTML

<div class="jbTitle">
      <h1>Site Title</h1>
    </div>
    <div class="jbMenu">
      <p>
        First Menu
        Second Menu
        Third Menu
        Fourth Menu
      </p>
    </div>
    <div class="jbContent">
    </div>

CSS

body {
  background: #fff;
  padding: 20px;
}
    body {
        margin: 0px;
        padding: 0px;
      }
      .jbTitle {
        text-align: center;
      }
      .jbMenu {
        text-align: center;
        background-color: yellow;
        padding: 10px 0px;
        width: 100%;
      }
      .jbContent {
        height: 2000px;
      }
      .jbFixed {
        position: fixed;
        top: 0px;
      }

JavaScript

var i=1;
$('p').each(function(){
	$(this).addClass('s'+i);
	i++;
});