- Messages
- 5,609
- Reaction score
- 250
- Points
- 63
I would like to use javascript to check if a certain html element is empty (I know it sounds ridiculous, just go with it )
So this:
Will be replaced with this:
I tried this, but it didn't work:
Any idea of how I can do this?
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!
So this:
Code:
<p id="checkme"></p>
Will be replaced with this:
Code:
<p id="checkme">There was no text here, but now there is!</p>
I tried this, but it didn't work:
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>
Any idea of how I can do this?
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!
Last edited: