Now Hiring: Are you a driven and motivated 1st Line IT Support Engineer?

Blog

Xóa inline style CSS bằng jQuery

jQuery

Xóa inline style CSS bằng jQuery

Mấy hôm trước, khi mình đang làm cho Accordion responsive ở màn hình mobile thì gặp phải một vấn đề: Làm thế nào để xóa inline style CSS của một element?!

Ví dụ:

<div id="box" style="width: 100px; height: 100px; background-color: #bada55;"></div>

Bây giờ, mình muốn xóa chỉ thuộc tính width của thẻ div#box này! Nhờ jQuery mà điều đó có thể thực hiện một các dễ dàng. Ta chỉ cần đặt giá trị width là một chuỗi rỗng.

jQuery('#box').css('width', '');

Hoặc ta có thể thể dùng JavaScript để xóa.

document.getElementById('box').style.width = '';

Okie, vấn đề đã được giải quyết 😀

Bạn có thể thử luôn dưới đây 😉

 

Leave your thought here

Your email address will not be published. Required fields are marked *

Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare