How to do it…

  1. Open the currently blank _recipe07-03-js.ejs and paste the code as follows:
<script> // plugin definition (function ($) { $.fn.classToggler = function (oldClass, newClass) { return this.each(function(i, elem) { var $currentIndex = $(elem); $currentIndex.toggleClass(oldClass + " " + newClass);  }); }; })(jQuery); // calling the plugin $('#switchNavbar').click(function() { $('.navbar') .classToggler("bg-faded", "bg-info") });</script>
  1. Now, open recipe07-03.ejs and paste the following code:
<div class="container"> <div class="mt-5"> <h1><%- title %></h1> <p>A Simple CSS Class Replacement jQuery Plugin.</p> </div><!-- /.container --> <button type="button" class="btn btn-default" id="switchNavbar" style="cursor: pointer"><span ...

Get Bootstrap 4 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.