Home > Article > Web Front-end > How to change a tag value in jquery
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")".
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标签新值"); // $("a").html("a标签新值"); }); }); </script> a标签超链接
[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!