In this tutorial, learn how to get div text content and HTML content using jQuery. You can use jQuery to find the text content of div and the HTML content of div.

You have to use the jQuery text() and html() to find the HTML content and the text content of div.

If you want to get div text content on click of the button, you need to access the button and the div. To access the element you have to use the jQuery selectors.

How to Get Div Text Content Using jQuery

The example contains the script and the HTML with div and button element. The script contains the jQuery click event to find the click of the button and execute the script code under the click event. Also, it contains the alert message box to show the text content in the alert message.

Output

This is the div to show example of div content.


The above example contains a div that contains the text and the HTML strong tag. If you want to get the text only, you have to use the text(). If you want to get the text as well as the strong tag, you have to use the html(). Click the button given above to get text content.

If you want to get the html content, keep reading and click the button given in the below example.

How to Get Div HTML Content Using jQuery

The below contains the html() to get HTML content of div using jQuery. If there is any HTML tag inside the div, the html() find and display the tag in the alert message box.

Output

This is the div to show example of div content.


Click the above button to get the HTML content of the div. You will get an alert message box that contains the HTML tag also.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.