jQuery > Attribute related method

.text() - Get set text of element in jQuery

How to get or set the text of element in jQuery?


To get or set the element text content (including the child elements), text() method can be used.

<script>
      $("#div3").html($("#div2").text());
  </script>

Above code snippet will set the text content of element “div2” as the html content to the element “div3”.

<script>
      $("#div3").text("This text is set by <b>jQuery</b> !");
  </script>

Above code snippet will set specified text to the element whose id is “div3”.

 Views: 4675 | Post Order: 34



Write for us






Hosting Recommendations