Home >Web Front-end >JS Tutorial >How to change tag attribute value using jquery
How to use jquery to change the tag attribute value: first use the p tag to create the test text in the file, and add the id attribute; then bind the onclick click event to the button button; finally use the [attr()] method Modify the attribute value of id.
The operating environment of this tutorial: Windows 7 system, jquery version 3.2.1. This method is suitable for all brands of computers.
How to use jquery to change the attribute value of a label:
1. Create a new html file and name it test.html, which is used to explain how jquery modifies the attributes of a label. .
2. In the test.html file, use the p tag to create a line of test text. The code is as follows:
# #3. In the test.html file, add an id attribute to the p tag. The attribute value is mytest. Next, we will use the jquery method to modify this attribute. 4. In the test.html file, use the button tag to create a button, bind the onclick click event to the button button, and when the button is clicked, execute editid() function. 5. In the js tag, create the editid() function. Within the function, obtain the p tag object through the element name and useattr() The method modifies the attribute value of id, for example, to mynewtest.
Related free learning recommendations:javascript (video)
The above is the detailed content of How to change tag attribute value using jquery. For more information, please follow other related articles on the PHP Chinese website!