$(selector).text() works wrongly.

$(selector).text() works wrongly.

Hi,
I used text method to replace text node of an element. But it replaces all text and HTML elements too.
Let say!
For an example:
  • I have like this <div id="test"> Some text <span> Whatever it is </span></div>.
  • I need to change $("#test") text node. So, I used $("#test").text("Something") I expected it will change only the text node of an element($("#test")) but it doesn't. It changes all of those elements in the container.
  • Then I inspected that object console.log($("#test")). It shows like this. Please refer screenshot.
  • It sets the text node object as a firstChild. It shows the value correctly. And wholeText value is "Some text ". but it does wrong action. why?
  • I clearly mention that I am going to change only the text node value by using the "text()" method.

Why it does like this?