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);".
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)
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>
Output result:
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!