1

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

3
  • You don't need "Espanol" Version here... I've added );, if it is not in your code, kindly remove it. Commented Oct 3, 2014 at 6:46
  • 1
    Why in firebug was remove but in DOM not? It's removed from DOM. View Page Source doesn't reflect actual DOM state. Commented Oct 3, 2014 at 6:47
  • try to check element if ($("#mydiv").length > 0) Commented Oct 3, 2014 at 6:48

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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.

1 Comment

Thanks for answering . The problem is Google . Google reads " h1 " of "div" (although the " div " is not visible to the user) and uses it as a key to the word SEO . The problem is that the div is loaded on all pages but not always display.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.