Reputation: 43
I have a problem with $( "#MiID" ).remove();
function.
I use:
$(document).ready(function () {
$( "#mydiv" ).remove();
});
In firebug
, the div
is removed, but if I click View Page Source
the div
appears there.
How can I resolve the problem?
Why in firebug
was remove but in DOM not?
UPDATE: The problem is Google . Google reads the contents of the div and google uses the " h1 " of "div" as a key word of my website . This div is repeated on every page of my website but do not know can correct that problem. I can just hide and unhide the div
Upvotes: 1
Views: 205
Reputation: 1045
Actually when the browser download DOM, it downloads all elements and then set the DOM, if any changes occur after the DOM downloaded it will only be on user end. It doesn't mean that u remove it by jquery so the element actually remove from the source code it just remove from the DOM on client and the origional downloaded source code remains same.
Upvotes: 0
Reputation: 70075
That is expected behavior. jQuery
can't alter your initial HTML source code (which is what View Source shows), only what the actual DOM is (which is what Firebug shows). Fortunately, you have no reason to care about the contents of the initial HTML source code in 99.9999% of web applications--you just care about what the DOM is, since that's what the user sees.
Upvotes: 3
Reputation: 53198
The element is indeed removed from the DOM tree when you use the remove()
function.
Viewing the source of page shows you the original content on the server, and does not take into consideration client-side modifications to the DOM.
Upvotes: 3