Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>JS Bin</title>
  </head>
  <body>
    <p class="box"></p>
    
    <button id="button">click me</button>
    <script src="https://code.jquery.com/jquery-2.0.3.js"></script>
  </body>
</html>
 
.box {
  width: 100px;
  height: 100px;
  border: 1px solid black;
  background-color: blue;
}
.red-background {
  background-color: red;
}
 
$(() => {
   // 1. SELECT an element with id of button
   // 2. LISTEN for a click event;   
   //    when the click event happens CALL the
   //    changeBackgroundColor function 
  
   $('#button').click(() => {
     
     // 3. SELECT all p tags 
     // 4. CALL the toggleClass method to 
     //  to 'toggle' the class of 'red-background'
     
     $('p').toggleClass('red-background')
   })
   
})
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x