Hi Bryan,

I threw something together pretty quickly, so I'm sure it could be further improved.

Here is a demo, based on your pastie code:

http://test.learningjquery.com/moveli.html

Here is the jQuery:

$(document).ready(function() {
  var moveLi = function() {
$('#suggestedCategories, #selectedCategories').find('li a').unbind('click').click(function() { var moveTo = $(this).parents('div')[0].id == 'suggestedCategories' ? '#selectedCategories ul' : '#suggestedCategories ul';
      $(this).parent().appendTo(moveTo);
      moveLi();
      return false;
    });
  };
  moveLi();
});



--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com



On Jan 10, 2008, at 10:13 AM, Bryank wrote:


Hi Everyone,

I will make this example as simple as possible.

I have  2 divs, each containing list items. When an item in box #1 is
clicked, I want to move it to box #2. When that same item is clicked
in box #2, I want to move it to box #1.

My co-worker and I are working on this and here is some code he put
together:
http://pastie.caboo.se/137728

My original method was using something like this:

$(document).ready(function() {

 $('#suggestedCategories ul li a').click(function() {
 $('#selectedCategoriesList').append('<li><a href="#"
onclick="removeItem(this); return false;">' + $(this).html() + '</ a></
li>');
$(this.parentNode).remove();
});

});
function removeItem(el) {
        $('#suggestedCategories ul').append('<li><a href="#">' + $(el).html()
+ '</a></li>');
        $(el.parentNode).remove();

}

I want to know if there is a cleaner easier way to pull this off then
what was pasted at:
http://pastie.caboo.se/137728

Thanks,
Bryan

Reply via email to