17 February 2023

In jQuery, the attr method is used to get or set the value of an attribute for an element. In vanilla JavaScript, you can use the getAttribute and setAttribute methods to achieve the same functionality.

Source code viewer
  1. var element = window.document.getElementById('element');
  2. var dataId = element.getAttribute('aria-label');
  3. element.setAttribute('aria-label', "my label");
Programming Language: Javascript