jQuery日本語リファレンス

jQuery does not mean Japanese Query...

Attributes/API/jQuery - Sample Code

text()


      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  
  <script>
  $(document).ready(function(){
    $(document.body).click(function(){
      alert($("div").text()); 
    });
  });
  </script>
  <style>
  p { color:blue; margin:8px; }
  b { color:red; }
  span { text-decoration: underline; }
  </style>
</head>
<body>
  <div>click <span>hrer</span> to show the result of text().</div>

  <div>The result is a string that contains the combined text contents of <strong>all</strong> matched elements. </div>
  <p>Hrer is a paragraph.</p>
  <div>This method works on both <strong>HTML</strong> and <b>XML</b> documents.<div>Even if it is XHTML as well</div></div>

</body>
</html>
	 
[実行結果]
[text() の説明へ]