Home > Web Front-end > JS Tutorial > How to replace the content in the middle of a tag with jquery

How to replace the content in the middle of a tag with jquery

WBOY
Release: 2021-11-30 11:57:57
Original
2314 people have browsed it

Jquery method to replace the content in the middle of the a tag: 1. Use the "$(a tag element)" statement to obtain the specified a tag element object; 2. Use the html() method to replace the content in the middle of the a tag. The syntax is "a tag element object.html (content to be replaced);".

How to replace the content in the middle of a tag with jquery

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

How jquery replaces the content in the middle of the a tag

We can replace the content in the middle of the a tag through the html() method. When a value is set using this method, it overwrites the content of all matching elements.

The syntax is as follows:

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

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(){
    $("#jquery").html("123");
  });
});
</script>
</head>
<body>
<a href="https://www.php.cn/course/list/19.html" target="_blank" id="jquery">jQuery视频教程</a>
<button id="btn1">替换a标签中间的内容</button>
</body>
</html>
Copy after login

Output result:

How to replace the content in the middle of a tag with jquery

Related video tutorial recommendations:jQuery video tutorial

The above is the detailed content of How to replace the content in the middle of a tag with 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