coffeecup Posted May 5, 2011 Share Posted May 5, 2011 I do not know why this will not work. i ran it thru firefox many times the syntax is correct. i ran the document write green beans thru and that shows on the doc. could someone please let me know what is wrong with this. thank you <script type="text/javascript"> var paraP = document.getElementsByTagName("p"); for (var i=0; i< paraP.length; i++) { var titleT = paraP[i].getAttribute("title"); if (titleT) alert(titleT); // if the human only writes alert (titleT) without the if (titleT) or any other logical not, alert on its own will not work } </script> <script type="text/javascript"> document.write("green beans"); </script> </head> <body> <h2>what to buy</h2> <p>the brown cow</p> <p>the barking dog</p> <p title="a gentle reminder">Don`t forget to buy this stuff.</p> <ul id="purchases"> <li>a tin of beans</li> <li>cheese</li> <li>milk</li> </ul> Link to comment https://forums.phpfreaks.com/topic/235641-do-not-know-what-the-problem-is/ Share on other sites More sharing options...
requinix Posted May 5, 2011 Share Posted May 5, 2011 Scripts in the execute before the document has been loaded. That means the s do not exist yet so getElementsByTagName("p") won't find anything. Simplest solution is to move the Link to comment https://forums.phpfreaks.com/topic/235641-do-not-know-what-the-problem-is/#findComment-1211151 Share on other sites More sharing options...
coffeecup Posted May 5, 2011 Author Share Posted May 5, 2011 Thank you requinix Link to comment https://forums.phpfreaks.com/topic/235641-do-not-know-what-the-problem-is/#findComment-1211166 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.