Home >Web Front-end >JS Tutorial >How to add tag attributes in jquery

How to add tag attributes in jquery

coldplay.xixi
coldplay.xixiOriginal
2020-11-19 16:51:223989browse

How to add tag attributes in jquery: first create the html tag element; then obtain the tag object in the js tag, and use the [attr()] method to add attributes to the tag object.

How to add tag attributes in jquery

How to add tag attributes in jquery:

1. Create a new html file and name it test.html. Used to explain how jquery adds attributes to tags.

How to add tag attributes in jquery

2. In the test.html file, introduce the jquery.min.js library file and successfully load the file before you can use the methods in jquery.

How to add tag attributes in jquery

3. In the test.html file, use the p tag to create a line of test text.

How to add tag attributes in 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 addsx() function.

How to add tag attributes in jquery

5. In the js tag, create the addsx() function. Within the function, obtain the p tag object through the element name, and use the attr() method to set the id of the p tag. for mypp.

How to add tag attributes in jquery

#6. Open the test.html file in the browser, click the button to view the source code and view the results.

How to add tag attributes in jquery

Related free learning recommendations: JavaScript (video)

The above is the detailed content of How to add tag attributes in jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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
Previous article:What is jQueryEasyUI?Next article:What is jQueryEasyUI?