Home  >  Article  >  Web Front-end  >  How to change a tag value in jquery

How to change a tag value in jquery

青灯夜游
青灯夜游Original
2022-05-25 15:59:333099browse

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:

$("选择器")

Example

 $("a")

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标签超链接

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!

Statement:
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