- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 do I display only the visible text with jQuery?
To display only the visible text, use the concept of − visible selector in jQuery. It selects the element currently visible. Following is the code −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initialscale= 1.0"> <title>Document</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> </head> <body> <div id="myDiv"> <span class="test" style="display:none"><b>Test Class</b></span> <span class="demo"> <b>Demo class</b></span> </div> <script> $('#myDiv').children(":visible").text() </script> </body> </html>
To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.
This will produce the following output displaying the visible text −
- Related Articles
- How do I select text nodes with jQuery?
- How do we display the visible width of a text area in HTML?
- How can I change the text color with jQuery?
- How to find the text visible on the button with JavaScript?
- Handling with only visible elements in Cypress
- jQuery :visible Selector
- How do we set the visible number of lines in a text area in HTML?
- How do we display inserted text in HTML?
- How to replace only text inside a div using jQuery?
- How do I use jQuery effects?
- How do I center the text in a Tkinter Text widget?
- How do we display a text area in HTML?
- How to Only Allow Numbers in a Text Box using jQuery?
- How do we include the direction of text display in HTML?
- How do I display tooltips in Tkinter?

Advertisements