- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get text contents of all matched elements using jQuery?
To get the text contents of all matched elements using jQuery, use the text() method. You can try to run the following code to get text contents of all matched elements using jQuery −
Example
<html> <head> <title>The Selector Example</title> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function() { $("#button1").click(function(){ var content = $("#pid2").text(); alert(content); }); }); </script> <style> .red { color:red; } .green { color:green; } </style> </head> <body> <p class = "green" id = "pid1">This is <i>first paragraph</i>.</p> <p class = "red" id = "pid2">This is second paragraph.</p> <button id="button1">Get</button> </body> </html>
- Related Articles
- How to insert content after each of the matched elements using jQuery?
- How to get the input value of the first matched element using jQuery?
- How to get a style property on the matched element using jQuery?
- Replacing all the matched contents Java regular expressions
- How to select a subset of the matched elements in jQuery()?
- How to get a set of elements containing all of the unique immediate children of each of the matched set of elements?
- How to prepend content to the inside of every matched element using jQuery?
- How to loop through all the iframes elements of a page using jQuery?
- jQuery contents()
- How to delete all the file contents using PowerShell?
- How to get selected text from a drop-down list (select box) using jQuery?
- How to remove all the elements from DOM using element ID in jQuery?
- How to list the subfolder contents using Get-ChildItem using PowerShell?
- How can I remove all elements except the first one using jQuery?
- How to use jQuery to get the value of HTML attribute of elements?

Advertisements