Reputation: 41
I know Some programs (like grease monkey) can modify DOM just after the DOM is loaded completely.
But Is it possible during the DOM is loading? or before loaded?
Upvotes: 3
Views: 6878
Reputation: 60737
Yes, it's possible.
Check out this example:
<div id="t">Some text</div>
<script>
document.getElementById('t').textContent = "Other text";
</script>
<div>Yay!</div>
The script part will modify the DOM even though the "Yay!" div hasn't loaded. It can only do that because the <div id="t">
is already loaded, though.
This is the extent of how much you can do.
If you want to insert something while the DOM is loading, you can use document.write
(this is the trick that most ads providers use to add the script tag wherever their snippet is added).
Upvotes: 1
Reputation: 2389
Maybe already answered here :
Chrome Extension : Modify DOM before loading
Is it ok to manipulate dom before ready state?
Possible to modify DOM during/before initial DOM parsing?
Upvotes: 2