Get the content of a paragraph and convert it to text in jQuery

Description

The following code shows how to get the content of a paragraph and convert it to text.

Example


<html>
<head>
<script
  src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {<!--from ww  w.j  a  v a2  s  . c om-->
    alert($("p").contents().text());

  });
</script>
</head>
<body>
<body>
  <p>
    Hello <span>span</span>data java 2s.com
  </p>

</body>
</html>

Click to view the demo





















Home »
  jQuery »
    jQuery Example »




Animation
DOM
Event
Form
List
Select
Style
Table
Utilities