Home > Web Front-end > JS Tutorial > How to change tag attribute value using jquery

How to change tag attribute value using jquery

coldplay.xixi
Release: 2020-12-22 16:07:24
Original
6483 people have browsed it

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.

How to change tag attribute value using jquery

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. .

How to change tag attribute value using jquery

2. In the test.html file, use the p tag to create a line of test text. The code is as follows:

How to change tag attribute value using jquery

# #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.

How to change tag attribute value using jquery

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.

How to change tag attribute value using jquery

5. In the js tag, create the editid() function. Within the function, obtain the p tag object through the element name and use

attr() The method modifies the attribute value of id, for example, to mynewtest.

How to change tag attribute value using jquery

#6. Open the test.html file in the browser and click the button to view the effect of the source code modification.

How to change tag attribute value using jquery

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template