17 February 2023

In jQuery, you can set CSS properties on an element using the css() method. To achieve the same thing in vanilla JavaScript, you can use the style property of the element.

Source code viewer
  1. // Get styles.
  2. var elementStyle = getComputedStyle(window.document.querySelector('.my-class-name'));
  3. // Add/edit style.
  4. window.document.querySelector('.my-class-name').style.backgroundColor = 'red';
  5. // Delete style.
  6. window.document.querySelector('.my-class-name').style.backgroundColor = '';
Programming Language: Javascript