How to Show Alert Text from Div using jQuery? | Code Snippet #29

Code Snippet #29: The code shows us how to produce alert box from a the div text. Simple jQuery method to get the text from div and show it in alert window. 

Show Alert Box From Div Using jQuery

So, how do you show alert text from div using jQuery? Isn’t it something dynamic? Yes, it is possible to show and dynamically fetch the text from any div you wish to show in your alert box.

Today, we will learn a simple code to:

  • Detect a click on the button.
  • Fetch the text from a div and show it in alert window.

DEMO: Click the button to pick the div text and show it in an alert window



There is no CSS for this code snippet.


In the HTML, we create a input field for a button and a div with class “alert” which contains the text to display in the alert box.

In jQuery, we detect click on the input of type button and use the below code to produce the alert:

This is a normal alert which references to the class “alert” and gets the text from that class and displays on an alert.

Hope you found this code snippet useful, please let us know your opinion and findings in the comments.


Vinod Suthersan is a enthusiastic web designer still learning new things on web designing. He loves designing, hunting new designs, blogging, and crazy about Internet. Know more

You may also like...