How to get the text inside an element using jQuery

  707 views   1 year ago jQuery

Use the jQuery text() method

You can simply use the jQuery text() method to get all the text content inside an element. The text() method also return the text content of child elements.

Let's take a look at an example to understand how this method basically works:

<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<title>jQuery Get Text Content of an Element</title>
<script src=""></script>
    // Show text content of plain paragraph
    // Show text content of formatted paragraph
    <p class="plain">The quick brown fox jumps over the lazy dog.</p>
    <p class="formatted">The <strong>quick</strong> brown fox <em><sup>jumps</sup></em> over the <a href="#">lazy dog</a>.</p>
    <button type="button" class="show-plain-text">Get Plain Text</button>
    <button type="button" class="show-formatted-text">Get Formatted Text</button>


Author : Harsukh Makwana
Harsukh Makwana

Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]

Related Articles