Get content with the text() and html() methods - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:text

Description

Get content with the text() and html() methods

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("#btn1").click(function(){
        console.log("Text: " + $("#test").text());
    });//from  w w w  . j a  v a 2  s  .c  om
    $("#btn2").click(function(){
        console.log("HTML: " + $("#test").html());
    });
});
</script>
</head>
<body>

<p id="test">This is some <b>bold</b> text in a paragraph.</p>

<button id="btn1">Show Text</button>
<button id="btn2">Show HTML</button>

</body>
</html>

Related Tutorials