JavaScript Jquery move element from a div to another jquery move element to another div,jquery move element up,

I have two lists: the first one is displayed on the left and the second on the right. I want that if I click on an element in the left, he is removed and he is prepended to the right list (and the opposite action)

This is my html:

<div class="cont">
   <div  id="groupL" class="innDiv">
       <div id="1" class="aaaL">Value 1</div>
       <div id="2" class="aaaL">Value 2</div>
   </div>
   <div  id="groupR" class="innDiv">
       <div id="4" class="aaaR">Value 4</div>
       <div id="3" class="aaaR">Value 3</div>
   </div>
</div>

This is the javascript source.

var clickLtoR  = function(n){
   _this = $('#'+n);
   $('#groupR').prepend('<div class="aaaR" id="'+n+'">'+_this.html()+'</div>');
  _this.remove();

}

var clickRtoL = function(n){
    _this = $('#'+n);
    $('#groupL').prepend('<div class="aaaL" id="'+n+'">'+_this.html()+'</div>');
    _this.remove();

}

$('.aaaL').click(function(){
    clickLtoR($(this).attr("id"));
});
$('.aaaR').click(function (){
    clickRtoL($(this).attr("id"));
});

If I click for example on "Value1", I need to move this div to the right.

It's works..but if I click again on the same element, for example following the previous example on the "value 1", this have not any associated click event and does not come back on the left list.

How to do to solve this problem and bind the click on the "new element"?

Here, the working code on JSFiddle http://jsfiddle.net/uw446/1/

Answer:1

http://jsfiddle.net/uw446/2/

$("div.el").on("click", function() {
    var $this = $(this);
    if ($this.hasClass("aaaL")) {
        $this.removeClass("aaaL").addClass("aaaR").prependTo("#groupR");
    } else {
        $this.removeClass("aaaR").addClass("aaaL").prependTo("#groupL");
    }
});

You are indeed overcomplicating this. The above should work flawlessly.

Answer:2

I'm trying to have my map zoom or expand to fit all markers when it updates as some are plotted off the screen and you can't see them. My code is as follows... $scope.loadMap = function () { ...

I'm trying to have my map zoom or expand to fit all markers when it updates as some are plotted off the screen and you can't see them. My code is as follows... $scope.loadMap = function () { ...

My background listener is chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) In chrome.contextMenus.onClicked listener, I want to use the message system,I call chrome....

My background listener is chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) In chrome.contextMenus.onClicked listener, I want to use the message system,I call chrome....

  1. chrome extension sendmessage example
  2. chrome extension sendmessage from content script to background
  3. chrome extension sendmessage not working
  4. chrome.extension.sendmessage
  5. chrome extension sendmessage response undefined
  6. chrome extension sendmessage callback
  7. chrome extension sendmessage async
  8. chrome extension sendmessage promise
  9. chrome extension sendmessage synchronous
  10. chrome extension sendmessage to tab
  11. chrome extensions sendmessage to content script
  12. chrome extension runtime sendmessage
  13. chrome extension popup sendmessage
  14. chrome extension send message to background
  15. chrome extension send message from content script to popup
  16. chrome extension send message from background to content
  17. chrome extension send message from popup to content
  18. chrome extension send message to popup
  19. chrome extension send message to background script
  20. chrome extension send message to web page

I have a doubt with javascript document.write method. Mostly when I use document.write() it shows me the content written with the method in a different page. For instance, if I write the command like ...

I have a doubt with javascript document.write method. Mostly when I use document.write() it shows me the content written with the method in a different page. For instance, if I write the command like ...

  1. document.write image display

I want to open another searchpage.html html page with slide effects for which i used anchor tag. <a id="add" href="searchpage.html" class="show_hide">Click</a> And js: $(document)....

I want to open another searchpage.html html page with slide effects for which i used anchor tag. <a id="add" href="searchpage.html" class="show_hide">Click</a> And js: $(document)....