Skip to content Skip to sidebar Skip to footer

Why Does Appending To Innerhtml In A Bookmarklet Overwrite The Entire Page?

I have this little bookmarklet: javascript:document.getElementsByTagName('div')[0].innerHTML+='Chuck Norris'; Now it's obviously supposed to take the very first div on the page, a

Solution 1:

You are not cancelling the action. add void 0; to then end.

javascript:document.getElementsByTagName("div")[0].innerHTML+="Chuck Norris";void 0;

Solution 2:

I'm not sure what the exact problem is, but I got it working by making a textNode and appending it:

javascript:var d=document.getElementsByTagName("div")[0];var n=document.createTextNode("Chuck Norris");d.appendChild(n);

Post a Comment for "Why Does Appending To Innerhtml In A Bookmarklet Overwrite The Entire Page?"