How to modify the content of a in jquery

藏色散人
Release: 2021-12-01 11:53:33
Original
2799 people have browsed it

How jquery modifies the content of a: 1. Set the attribute value of the selected element through the jquery attr() method; 2. Set the text content of the selected element through the jquery text() method.

How to modify the content of a in jquery

The operating environment of this article: windows7 system, jquery3.2.1 version, DELL G3 computer

How to modify the content of a with jquery?

jquery modifies the href link and text of a tag

The following is the code to modify the href link and text of a tag:

<script type="text/javascript" src="http:/keleyi.com/keleyi/pmedia/jquery-1.9.1.min.js"></script>
Copy after login

Original link:

<a href="http://keleyi.com" id="home_keleyi_com">柯乐义</a>
Copy after login

Modify the href link of the a tag:

$(&#39;#home_keleyi_com&#39;).attr(&#39;href&#39;,&#39;http://keleyi.com&#39;);
Copy after login

Modify the text:

$("#home_keleyi_com").text(&#39;柯乐义首页&#39;);
Copy after login

The modified link is:

<a href="http://keleyi.com" id="home_keleyi_com">柯乐义首页</a>
Copy after login

The following is the complete link Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jquery修改链接--柯乐义</title>
<script type="text/javascript" src="http://keleyi.com/keleyi/pmedia/jquery-1.9.1.min.js"></script>
</head>
<body>
Copy after login

jquery to modify the href link and text of the a tag, first click the link below
then click the "Change" button, then click the link below once, pay attention to opening the page twice Different:


原文
Copy after login

Recommended learning: "jquery video tutorial"

The above is the detailed content of How to modify the content of a 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!