Home > Web Front-end > JS Tutorial > body text

How to modify the value of child elements in jquery

WBOY
Release: 2022-09-09 19:26:05
Original
2967 people have browsed it

Jquery method to modify the value of a sub-element: 1. Use the "$("element id value")" statement to obtain the sub-element object according to the specified id value; 2. Use the html() method to modify the obtained sub-element The element object value is sufficient, and the syntax is "child element object.html("modified value");".

How to modify the value of child elements in jquery

The operating environment of this tutorial: windows7 system, jquery3.6.1 version, Dell G3 computer.

jquery method of modifying the value of a child element

We can use the html() method to return or set the content of the selected element (inner HTML) .

If this method does not set parameters, the current content of the selected element is returned.

The syntax is:

$(selector).html(content)
Copy after login

Among them, content is an optional parameter. Specifies the new content of the selected element. This parameter can contain HTML tags.

jquery only needs to use the html method to modify the value of a child element. The syntax is "element object.html (modified value);"

Let's take a look at it through an example:

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $(".btn1").click(function(){
    $("p").html("Hello world!");
  });
});
</script>
</head>
<body>
<p>This is another paragraph.</p>
<button class="btn1">改变 p 元素的内容</button>
</body>
</html>
Copy after login

Output result:

How to modify the value of child elements in jquery

For more programming-related knowledge, please visit: Programming Video! !

The above is the detailed content of How to modify the value of child elements 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!