Reputation: 3037
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
</script>
<div id="divTest1"></div>
<script type="text/javascript">
$("#divTest1").text("Hello, world!").css("color", "blue");
console.log($("#divTest1").text("Hello, world!"));
</script>
In chrome->console, it shows: [div#divTest1, context: document, selector: "#divTest1", jquery: "1.10.1", constructor: function, init: function…]
Here(http://api.jquery.com/text/) it is said: .text() method returns the value of text and CDATA nodes as well as element nodes.
Questions:
how to find te value of text in console?
what is the difference between CDATA nodes and element nodes?
Upvotes: 1
Views: 73
Reputation: 123739
$("#divTest1").text("Hello, world!")
is a setter for text()
you need to use getter like this.
$("#divTest1").text()
When you do console.log($("#divTest1").text("Hello, world!"));
it will return the jquery object over the DOM element for chaining purpose after setting the text and thats what you are seeing in the console.
Try this:
$(function(){
$("#divTest1").text("Hello, world!").css("color", "blue");
console.log($("#divTest1").text());
});
For your second question see this:
CDATA sections are used to escape blocks of text that would otherwise be treated as markup. In web development they're often used for including unpredictable HTML inside another form of XML, or for programmatic code like scripts and style information.
Upvotes: 3