With this, you can dynamically change one or several attributes of an element. The attr()method can be used to either fetch the value of an attribute from the first element in the matched set or set attribute values onto all matched elements. Description: Select elements that either don't have the specified attribute, or do have the specified attribute but not with a certain value. This Jquery attr() method is specifically used to set attributes and values of selected elements. jQuery data attribute selector for closest parent, Here, it is not required to verify value of data-testing, but to get the first parent in hierarchy having "testing" set as its data attribute. If the attribute already exists, its value is updatedwith the specified value. When the change event occurs, the change method attaches a function with it to run. In the above attr() method example, When you click on button after that open a popup box with data-id and data-text attribute values. You then return the string you wish to use as the new attribute value from the function. An element's data-* attributes are retrieved the first time the data() method is invoked upon it, and then are no longer accessed or mutated (all values are stored internally by jQuery). You can add/change several attributes at once for an element (or elements) by supplying a map of attribute names and values. Alternatively, you can also use the jQuery data() method (jQuery version >= 1.4.3), to get the data-attribute of an element using the syntax like $(element).data(key).. That means in the above example to get the data-id using data() method you can use the statement like $(this).data("id").Key is the rest of the part after removing data-. Let’s say the following is our input type with value, “John Smith” −, You need to use the concept of attr(). To run the above program, save the file name “anyName.html(index.html)” and right click on the If you click the save button, your code will be saved, and you get a URL you can share with others. It can also be used to change the value. Type: String. The jQuery attr() method is used to get the value of an attribute. How to change the value of an attribute in javascript? To this purpose, jQuery offers the extremely flexible and useful method attr(). Note: This event is limited to elements,