views:

42

answers:

1

I have got a list of elements that im trying to delete using the .remove() from jQuery.It does delete the elements while viewing the page on the browser but I was wondering if its possible to delete the elements in its entirety from the page? So when i open the file in an editor later on, those elements shouldn't appear.

And one thing I have noticed that was even though the .remove() deletes the elements, the deleted elements comes back once i refresh the page. Would some be kind enough to give an explanation for this ?

I have posted below the code i've written :-

HTML:

<ul class="listServices">

            <li class="date">03rd October Sunday </li>
            <li class="subject">maths</li>
            <li class="subject">english</li>
            <li class="subject">physics</li>

</ul>
<div class="btn">delete</div>

Jquery:

$(document).ready(function() {
 $('.btn').click(function () {
      $curr = $(this).prev();
     $curr.remove();
    });
    });
+2  A: 

No. That is not possible using client-side JavaScript alone.

Remember that HTML files are served up by a server and the file lives on that server.

The JavaScript is running on the client-side. When you remove an element using the DOM, you're simply modifying the client-side DOM.

If you want the file to be modified on the server, you would need to implement some sort of server side solution so that the JavaScript could call the code on the server and then make the necessary changes there.

Justin Niessner
@justin thanks for ur prompt answer, but what exaclty is the use of .remove() ? im just a bit confused to where it should applied
manraj82
@manraj82 - Typically it is used in dynamic web applications when you want to manipulate the page without having to repost back to the server.
Justin Niessner