jQuery Examples - $("p").text("<i>Hello World</i>")
Description
This would set "<I>Hello World</I>" as text content of the matching <p> elements.
Syntax
Here is the simple syntax to use this method −
selector.text(value);
Parameters
Here is the description of all the parameters used by this method −
value This is the value to be set to the matched element.
Example
Following example would set "<I>Hello World</I>" as text content of the matching <p> elements.
Live Demo
<html>
<head>
<title>The jQuery Example</title>
<script type = "text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
<script type = "text/javascript" language = "javascript">
$(document).ready(function() {
$("p").text("<i>Hello World</i>");
});
</script>
<style>
.red { color:red; }
.green { color:green; }
</style>
</head>
<body>
<p class="red" id = "pid1">This is first paragraph.</p>
<p class="selected" id = "pid2">This is second paragraph.</p>
<div id = "result1"></div>
</body>
</html>
This will produce following result −
jqueryexamples_attributes.htm
Advertisements