Search code examples
htmlclassonerror

change class of images via onError


When using JavaScript and HTML why wont this work to change the class of an image if it is from a broken url?

onError="this.style.display=\'none\';this.class=null;"

i have also tried this:

onError="this.style.display=\'none\';class=null;"

and

onError="this.style.display=\'none\';class='';"

what could work?


Solution

  • Try this.className instead of this.class or class .

    <img src="/abc.png" class="random" onError="this.style.display='none';this.className='';" />