Home >Web Front-end >JS Tutorial >How to modify the value of a row in jquery
Jquery method to modify the value of a certain row: 1. Use the eq() method to obtain the specified row element object, the syntax is "element object.eq (index of the row element)"; 2. Use the html() method to To modify the value of the specified row element object that has been obtained, the syntax is "row element object.html (modified value)".
The operating environment of this tutorial: windows7 system, jquery3.2.1 version, Dell G3 computer.
How jquery modifies the value of a certain row
We can use the html method and eq() method to modify the value of a certain row.
eq() method returns the element with the specified index number of the selected element. Index numbers start with 0, so the index number of the first element is 0 (not 1).
The syntax is:
$(selector).eq(index)
html() method returns or sets the content of the selected element (inner HTML). If this method does not set parameters, it returns the current content of the selected element.
The syntax is:
$(selector).html(content)
Let’s take an example to see how to modify the value of a certain row. The example is as follows:
<html> <head> <script type="text/javascript" src="/jquery/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(".btn1").click(function(){ $("tr").eq(0).html("<td>hello</td>"); }); }); </script> </head> <body> <table border="1"> <tr> <th>Month</th> </tr> <tr> <td>January</td> </tr> <tr> <th>Month</th> </tr> <tr> <td>January</td> </tr> </table> <button class="btn1">改变第一行的元素的内容</button> </body> </html>
Output result:
Recommended related video tutorials: jQuery video tutorial
The above is the detailed content of How to modify the value of a row in jquery. For more information, please follow other related articles on the PHP Chinese website!