Home > Web Front-end > JS Tutorial > How to modify the value of a row in jquery

How to modify the value of a row in jquery

WBOY
Release: 2021-12-01 09:51:30
Original
2530 people have browsed it

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

How to modify the value of a row in jquery

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)
Copy after login

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)
Copy after login

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>
Copy after login

Output result:

How to modify the value of a row in jquery

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!

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