Home  >  Article  >  Web Front-end  >  How to modify the value of td in jquery

How to modify the value of td in jquery

WBOY
WBOYOriginal
2022-03-16 16:07:042843browse

In jquery, you can use the html() method to modify the value of td. The function of this method is to set or return the content of the selected element. The syntax is "td element object.html('td modified value ')".

How to modify the value of td in jquery

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

How does jquery modify the value of td

In jquery, the value of td in the table is mainly modified through the html() method. This method supports the modification of text content and also supports the modification of html content. Revise.

Create a new html file, named test.html, to explain how jquery modifies the value in the td in the table. Only after introducing the jquery.min.js library file and successfully loading the file can you use the methods in jquery.

Use table, tr, td tags to create a table with two rows and two columns, and set its border to 1px. Use the button tag to create a button with the button name "Modify td value".

Bind the onclick event to the button button. When the button is clicked, the edittd() function is executed.

In the js tag, create the edittd() function. Within the function, obtain the td object collection through the element name td, use the eq(2) method to obtain the third td object, and then use the html() method to modify it. The value of td. For example, here the value of td is modified to 3.

How to modify the value of td in jquery

Open the test.html file in the browser and click the button to see the effect.

How to modify the value of td in jquery

After clicking the button:

How to modify the value of td in jquery

Summary:

1. Create a test.html file .

2. In the file, use the table, tr, and td tags to create a table with two rows and two columns, and use the button tag to create a button to trigger the execution of the js function.

3. Create a function in the js tag. Within the function, obtain the td object. Use the eq() method to obtain the first td object, and then use the html() method to modify the value of the td.

Notes

The eq() method starts from 0, eq(0) represents the first element object, eq(1) represents the second element object, and so on.

Recommended related video tutorials: jQuery video tutorial

The above is the detailed content of How to modify the value of td 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