Search code examples
javascriptjquerycsstoggleclass

.parent().toggleClass not working


I have a fiddle right here: https://jsfiddle.net/qxnk05ua/2/

When I click the button, I want the background to change color, very simple. Why does it not work?

Javascript:

$(document).ready(function(){
  $('.block button').click(function(){
    $(this).parent().toggleClass('active');
  });
});

Solution

  • Please add jquery library in your HTML

    https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.js