Home >Web Front-end >Front-end Q&A >How to modify title value in jquery

How to modify title value in jquery

青灯夜游
青灯夜游Original
2022-04-28 15:03:074982browse

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");".

How to modify title value in jquery

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

#b2386ffb911b14667cb8f0f91ea547a7 tag defines the title of the document and is required in all HTML documents.

b2386ffb911b14667cb8f0f91ea547a7 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

You can use # to modify the title tag value ##text()

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>

2. jquery modifies the title attribute value

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. <pre class="brush:html;toolbar:false">&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset=&quot;UTF-8&quot;&gt; &lt;script src=&quot;js/jquery-1.10.2.min.js&quot;&gt;&lt;/script&gt; &lt;script type=&quot;text/javascript&quot;&gt; $(document).ready(function() { $(&quot;button&quot;).click(function() { $(&quot;div&quot;).attr(&quot;title&quot;,&quot;新title值&quot;); }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div title=&quot;这是title属性&quot;&gt;这是一个测试文本&lt;/div&gt; &lt;br&gt;&lt;br&gt; &lt;button&gt;修改元素的title属性&lt;/button&gt; &lt;/body&gt; &lt;/html&gt;</pre>

How to modify title value in jquery[Recommended learning:

jQuery video tutorial

, web front-end video

The 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!

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