Add and Remove class Name javascript, thêm hoặc xóa class trong javascript

Thảo luận trong 'Lập trình Javascript, js' bắt đầu bởi seolagi, 8/10/22.

  1. seolagi
    Tham gia ngày:
    16/4/14
    Bài viết:
    1,028
    Đã được thích:
    80
    Điểm thành tích:
    48
    Để Add and Remove a class Name javascript, thêm hoặc xóa class trong javascript các bạn sử dụng code sau. Với code thêm hoặc xóa 1 class name trong javascript vô cùng đơn giản như sau:

    Xóa/Remove 1 class Name bằng JavaScript
    HTML:
    function myFunction() {
      var element = document.getElementById("myDIV");
      element.classList.remove("mystyle");
    } 
    Demo: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_remove_class

    Thêm/Add 1 class Name bằng JavaScript
    HTML:
    function myFunction() {
      var element = document.getElementById("myDIV");
      element.classList.add("mystyle");
    } 
    Demo: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_add_class
     
    Cảm ơn đã xem bài:

    Add and Remove class Name javascript, thêm hoặc xóa class trong javascript



Chủ để tương tự : Remove class
Diễn đàn Tiêu đề Date
Lập trình Javascript, js Jquery remove all html from string, xóa tất cả ký tự html trong chuỗi như thế nào? 25/1/20
Lập trình Javascript, js Remove Readonly trong TextBox bằng js, javascript như thế nào 8/8/18
Lập trình Javascript, js Xóa remove height, width css trong jquery như thế nào ? 2/2/18