jQuery: Toggle Class

by ian_smithz

HTML

<button id="changer">Change the Divs</button>

<div></div>
<div></div>
<div></div>

CSS

div {
    background-color: red;
    margin: 10px;
    height: 100px;
    width: 100px;
}

.circle {
    background-color: gold;
    border-radius: 50%;
    float: left;
    height: 75px;
    width: 75px;
}

JavaScript

// select the button
// assign a click event to the button
$('#changer').click(function(){

    // when the button is clicked
    // toggle the "circle" class on all divs
    $('div').toggleClass('circle');

});