...

View Full Version : not getting text between p tags



hiral.und
11-29-2012, 06:38 AM
<html>
<head>
<title>JavaScript String toLowerCase() Method</title>
</head>
<body>
<script type="text/javascript">
alert(document.getElementById("demo").value);
//var lstr = str.toLowerCase();
//document.getElementById("demo").innerHTML = lstr;
</script>
<p id="demo">EARTH IS ROUND</p>
</body>
</html>

in above code i want to access string EARTH IS ROUND IN ALERT BOX

devnull69
11-29-2012, 07:15 AM
Your javascript code is before the <p id="demo"> element, so it will be executed before this element even exists. So getElementById("demo") will not be able to find it and will fail.

Solutions:
1 - Move the <script> tag below the <p> element, right before the </body> OR
2 - Use window.onload = function() { // your code here} so that your code will only be executed after the page finished loading (including images and other external elements)

felgall
11-29-2012, 07:40 AM
alert is for debugging only - don't forget to remove it before your page goes live.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum