jQuery addClass example

Change class name on click in jQuery

by abdulpathan

HTML

<img id="test" class="test-img">

CSS

.test-img {
  height: 100px;
  width: auto;
}

JavaScript

jQuery(document).ready(function() {
  jQuery('#test').attr('src', 'https://www.gstatic.com/webp/gallery3/2.png');
  console.log(jQuery('#test').outerWidth());
  console.log(jQuery('#test').outerHeight());
});