Brief Explanation: I have div1 and div2 onside a <div>. On right click i open context menu which has a button switch.
On clicking this button i want div1 and div2 to switch positions,
attached pic for your reference:

here is my code:
$(document).on("contextmenu", "div", function(event) {
// alert("right clicked");
event.stopPropagation();
this.clickedElement = $(this);
event.preventDefault();
$(this.clickedElement).addClass('selecteddiv');
$(".custom-menu4").show();
$(".custom-menu4 li").unbind().click(function() {
switch ($(this).attr("data-action")) {
case "second":
$(".custom-menu4").hide();
$(".selecteddiv").removeClass('selecteddiv');
break;
case "first":
alert("clicked switch");
break;
}
})
// alert("add");
});
.selecteddiv {
border: 1px solid rgb(180, 13, 172);
}
.custom-menu4 {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="click" style="padding: 20px">
<div class="switch">Hello</div>
<div class="switch">World</div>
</div>
<ul class='custom-menu4'>
<li data-action="first">Switch</li>
<li data-action="second">Cancel</li>
</ul>
link to jsfiddle
On clicking the switch button, the div1 should switch position with div2, i mean in whatever positions they are, they should switch.
Please help.