How to modify the title value in jquery: 1. Use text() to modify the title tag value, the syntax is "$("title").text("new value");"; 2. Use attr( ), you can modify the title attribute value, the syntax is "element.attr("title","new value");".
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
In HTML, there are two types of title values:
The content value of the title tag
The attribute value of the title attribute
So how to use jquery to modify these two title values? Let me introduce to you
1. jquery to modify the title tag value## The
#You can use # to modify the title tag value ##text()Element:
- Defines the title in the browser toolbar
- Provided that the page is The title when added to favorites
- The page title displayed in the search engine results
Method. The text() method returns the text content of the selected element. Example:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>文档的旧标题</title> <script src="js/jquery-1.10.2.min.js"></script> <script> $(document).ready(function() { $("button").click(function() { $("title").text("新的文档标题"); }); }); </script> </head> <body> <button>修改title文档标题</button> </body> </html>
The title attribute specifies additional information about the element.
This information usually displays a tooltip text when the mouse is moved over the element.
To modify the value of the title attribute, you can use the
attr() method, which can set the value of the specified attribute of the selected element. <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("button").click(function() {
$("div").attr("title","新title值");
});
});
</script>
</head>
<body>
<div title="这是title属性">这是一个测试文本</div>
<br><br>
<button>修改元素的title属性</button>
</body>
</html>
[Recommended learning:
jQuery video tutorialThe above is the detailed content of How to modify title value in jquery. For more information, please follow other related articles on the PHP Chinese website!