Click here to Skip to main content
15,897,718 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello ALL,

I am using this javscript library for pop up messages in my project
http://fabien-d.github.io/alertify.js/[^]


The issue i am having is that i am unable to display a message contained in a div in an alert pop up box.

HTML
<div id ="mydiv"> Display this message in an alert box</div>
<button > show message </button>

JavaScript
<script type="text/javascript">

            function message() {
                alertify.alert(document.getElementById("mydiv").innerHTML);
            }


        </script>

When the page loads .. the message is displayed on the page instead of in a pop up box and when i click to display the alert pop up , there is nothing in it.

What could i be doing wrong??
Posted

1 solution

Give the <div> and id.
Get the contents of the <div>
via:

var divText = document.GetElementById('theID').innerHTML;
Then put that in your alert:

(Here's where you went wrong: )

window.alert(divText);

not alertify.alert(divText);

Also, go to W3Schools and check out their javaScript tutorial.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900