How to change a tag value in jquery

青灯夜游
Release: 2022-05-25 15:59:40
Original
3112 people have browsed it

Change method: 1. Select the a tag, the syntax "$("selector")" will return a jQuery object containing the a tag; 2. Use text() or html() to modify the specified a tag The content value of the object, the syntax is "a element object.text("new content value")" or "a element object.html("new content value")".

How to change a tag value in jquery

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

jquery method of changing a tag value

1. Select a tag

Syntax:

$("选择器")
Copy after login

Example

 $("a")
Copy after login

is to use the element selector to select the a tag, which will return a jQuery object containing the a tag.

2. Use text() or html() to modify the tag content

  • The text() method can rewrite the text content of all matching elements. .

  • html() method rewrites the content of the selected element (innerHTML)

Example:




	
		
		
		<script>
			$(document).ready(function() {
				$("button").click(function() {
					$("a").text("a标签新值");
					// $(&quot;a&quot;).html("a标签新值");
				});
			});
		</script>
	

	
		a标签超链接

Copy after login

How to change a tag value in jquery

[Recommended learning: jQuery video tutorial, web front-end video]

The above is the detailed content of How to change a tag value 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