Bagaimana cara mengganti value dari atribut class menggunakan Javascript atau Jquery?

Misal saya punya tombol

<button class="tombol">
  <i class="fas fa-eye"></i>
</button>

Nah, setelah tombol di klik, saya ingin mengganti class "fa-eye" menjadi class "fa-eye-slash"

avatar feriirawan
@feriirawan

1 Kontribusi 1 Poin

Diperbarui 3 tahun yang lalu

1 Jawaban:

<div>pakai jquery<br><figure data-trix-attachment="{&quot;contentType&quot;:&quot;image/png&quot;,&quot;filename&quot;:&quot;jQ_ElmAttClass.png&quot;,&quot;filesize&quot;:43235,&quot;height&quot;:528,&quot;url&quot;:&quot;https://i.ibb.co/Cm2T488/j-Q-Elm-Att-Class.png&quot;,&quot;width&quot;:856}" data-trix-content-type="image/png" data-trix-attributes="{&quot;presentation&quot;:&quot;gallery&quot;}" class="attachment attachment--preview attachment--png"><img src="https://i.ibb.co/Cm2T488/j-Q-Elm-Att-Class.png" width="856" height="528"><figcaption class="attachment__caption"><span class="attachment__name">jQ_ElmAttClass.png</span></figcaption></figure><br><br>pakai vanila javascript<br><figure data-trix-attachment="{&quot;contentType&quot;:&quot;image/png&quot;,&quot;filename&quot;:&quot;JS_ElmAttClass.png&quot;,&quot;filesize&quot;:50523,&quot;height&quot;:528,&quot;url&quot;:&quot;https://i.ibb.co/1fhDbnY/JS-Elm-Att-Class.png&quot;,&quot;width&quot;:976}" data-trix-content-type="image/png" data-trix-attributes="{&quot;presentation&quot;:&quot;gallery&quot;}" class="attachment attachment--preview attachment--png"><img src="https://i.ibb.co/1fhDbnY/JS-Elm-Att-Class.png" width="976" height="528"><figcaption class="attachment__caption"><span class="attachment__name">JS_ElmAttClass.png</span></figcaption></figure></div>

avatar soeleman
@soeleman

120 Kontribusi 147 Poin

Dipost 3 tahun yang lalu

Login untuk ikut Jawaban