jQuery remove() and append() dilemma

diabolo

Community Advocate
Community Support
Messages
1,682
Reaction score
32
Points
48
I didn't exactly know how to phrase my problem, so i just wrote dilemma. :]
http://jsfiddle.net/imHavoc/kGKJJ/9/

My Dilemma:
  • When you 'delete' any li from the Board or Admin it should go to Uncategorized. Good.
  • When you 'delete' from Uncategorized, it should remove the li entirely. So-so.
The native li's in Uncategorized follow the function, but any li that comes from Board or Admin still follows its original function and gets appended to the end of the list.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
You also have a problem with moving Uncategorized to Admin and then deleting. It removes that li when it probably should move it back to Uncat.

click handler should check the div's parent's parent's id. If it is "uncategorized", then delete. Otherwise move to "uncategorized"
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Instead of walking up the DOM tree and checking the ID of a specific ancestor, you could use closest or parents to check whether any ancestor has the ID of interest.

Also, rather than checking the ancestor yourself, you can use live to dynamically match the element selector a listener is bound on.

Code:
    jQuery('#manage div.remove').live('click', function() {
        jQuery('ul#uncategorized').append(jQuery(this).parent());
    });

    jQuery('#uncategorized div.remove').live('click', function() {
        jQuery(this).closest('li').remove();
    });
 

callumacrae

not alex mac
Community Support
Messages
5,257
Reaction score
97
Points
48
Instead of walking up the DOM tree and checking the ID of a specific ancestor, you could use closest or parents to check whether any ancestor has the ID of interest.

Also, rather than checking the ancestor yourself, you can use live to dynamically match the element selector a listener is bound on.

Code:
    jQuery('#manage div.remove').live('click', function() {
        jQuery('ul#uncategorized').append(jQuery(this).parent());
    });

    jQuery('#uncategorized div.remove').live('click', function() {
        jQuery(this).closest('li').remove();
    });

Are there any languages you don't know? :(

~Callum
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Snobol (sadly), Cobol (happily).
 
Last edited:
Top