I would like to use javascript to check if a certain html element is empty (I know it sounds ridiculous, just go with it :P)
So this:
Will be replaced with this:Code:<p id="checkme"></p>
I tried this, but it didn't work:Code:<p id="checkme">There was no text here, but now there is!</p>
Any idea of how I can do this?Code:<p id="checkme"></p> <script type="text/javascript"> var old = document.getElementById("checkme").firstChild; var new = document.createTextNode("TEST"); if(old.length == 0) { document.getElementById("checkme").replaceChild(new, old); } </script>
The way I'm trying to do this requires the <script ...> directly before or after the <p> tag, although adding a script to the <head> is possible too.
Thanks!


LinkBack URL
About LinkBacks
Reply With Quote


