tags:

views:

240

answers:

6

I'm trying to remove a table row using jQuery, and while it disappears from the screen, and therefore, appears to work, in Firebug, I can still see the code for it. There are form elements in this row, and so, I want to understand whether the row is truly being deleted or not, because I wouldn't want those values submitted. So, does remove really remove? Below is the code I'm using... Maybe I'm doing it wrong?

if($('.delete')) {
            $(".delete").live('click', function(event) {
                $(this).closest('tr').remove();
            });
        }
+6  A: 

The source of a page doesn't update with Javascript functions. If you inspect the DOM in Firebug you should be able to see the changes reflected.

ck
I am looking in firebug... And, I still see the code for that particular remove there. So, perhaps something is wrong with how I'm doing it? Is there anything obvious from what I posted?
phpN00b
Are you looking at the DOM and not the source?
ck
For clarification to ck's note, the living DOM is parsed and structured in a tree in Firebug's main window, whereas the code you see in the HTML section or the Script section is the static HTML as initially loaded. Whenever JS changes are made to the structure, you see a yellow highlight on the area being changed (and, consequently, all the way up the tree).
dclowd9901
A: 

Yes, jQuery's remove() does really remove the elements from the DOM.

There probably is something wrong in your code.

frunsi
+1  A: 

It removes the element completely from your DOM. I think you may be looking at the wrong element, because if it is in fact being removed on your screen, firebug should reflect the change.

Your code looks fine.

.Remove() Reference

Jon
A: 

I'm having the same issue with the remove() function. The documentation for jQuery that's been linked doesn't mention it at all, but there is an issue.

The topic starter already said (twice) that he's viewing the DOM through FireBug (and not View Source) so please read before asking the same questions again, guys.

From what I've gathered, jQuery removes the element outside of the object. This, in essence, removes it from the document view but it does not totally move it out of the DOM. If you were to test for the existance of that element again it would return TRUE even though it's been moved.

We're not seeing things wrong either, we're looking in Firebug directly and watching as the element gets moved to the top of the document (right before ) - something is indeed wrong.

Anyone have any idea how to get around (or fix) this?

-Age

Ageman20XX
That is definitely not correct jquery behavior. I would suggest reducing your code to a minimal example of the error which you can post here.
mikerobi
A: 

That's right. The remove() method doesn't remove the elements. In "jQuery in Action" is written that "Note that, as many other jQuery commands, the wrapped set is returned as the result of this command. The elements that were removed from the DOM are still referenced by this set (and hence not yet eligble for garbage collection) and can be further operated upon using other jQuery commands... " I've been searching and it doesn't seem to be a jQuery that actually removes the elements. So I think you should do it using the old DOM JavaScript functions.

Fabrix
A: 

Yes it does.

I was playing with it the other day. You can see in firebug (and other browser debuggers) that the element disappears.

Keyo