JSFiddle - React, Tailwind, and code Playground

HTML

<img src="img/gavel.png" alt="" id="bg_img">

CSS

#bg_img {
    width: 100%;
    z-index: 1;
    border: 1px #000 solid;
    height:80%;

}

.imgMobile {
    display: none;
    width: 100%;
    z-index: 1;
    margin-left: -100;
}

JavaScript

if( window.innerWidth < 770 ) {
	  document.getElementById("bg_img").className = "imgMobile";
      alert("On Mobile");
	}else{

	  alert("Not on Mobile");
	}