Viks
Viks

Reputation: 958

Deleting completely a html element

I am aware of .remove() , I am using it and its working fine, I mean its removing the element which I want. But I think it doesn't removes it permanently. On right clicking in browser window selecting View page source I am still able to see those removed elements. I want to remove them completely or say permanently. Please help.

Upvotes: 2

Views: 3815

Answers (5)

user2189779
user2189779

Reputation:

You Cannot permenantly remove the dom elements using jquery or javascript. .remove() is totally different from your logic. just it removes temporary hide from the dom elements suppose you refresh the page it comes again it is jquery magic.

Upvotes: 1

Rohit Agrawal
Rohit Agrawal

Reputation: 5490

Page Source and DOM are two different different things, whenever you edit the elements or remove them it get removes from DOM and not from page source. That means The javascript manipulate the DOM not the source which come from the server.

DOM: The Document Object Model (DOM) is an application programming interface (API) for valid HTML and well-formed XML documents.

The view source always shows the content came from the server initially without any modification. Use DEVELOPER CONSOLE in browsers to see the live DOM manipulation.

Note: Press F12 to enable console on major browser

Upvotes: 2

Maurice Perry
Maurice Perry

Reputation: 32831

View page source shows the content of the original HTML file, as returned by the HTTP server. The DOM can be altered with javascript, but the source will not change.

Upvotes: 1

Praveen
Praveen

Reputation: 56509

view source render the code within the page that you have written(static)

for dynamic changes/view inspect the elements tab in developer tools.

Upvotes: 1

CRABOLO
CRABOLO

Reputation: 8793

.remove() removes them completely. The reason you still seem then in the view page source is because the page source does not change based on javascript. The page source shows how the page originally looked when it was first loaded, not how it currently is.

If you look in the developers console, you will see that they are no longer there.

Likewise, if you dynamically add a new element with javascript/jquery, it will not show that element in the page source.

Upvotes: 7

Related Questions