1

I* have two <div> containers which needs to interchange their position of display on the change of a dropdown value.

So, how can this be achieved using Jquery?

bewlow are the two div containers who display position is needed to be interchanged

<div id="first"><p>I will be displayed on second place on dropdown's particular value</p></div>

<div id="second"><p>I will be displayed on first place on dropdown's same value for which first div is placed at second position</p></div>
OM The Eternity
  • 15,694
  • 44
  • 120
  • 182

2 Answers2

3

Simple Using Javascript

<script>

function interchange()
{
 var strDiv1Content = document.getElementById('first').innerHTML;
 var strDiv2Content = document.getElementById('second').innerHTML;

 document.getElementById('first').innerHTML = strDiv2Content;
 document.getElementById('second').innerHTML = strDiv1Content;

}

</script>

using jQuery

<script>
function interchange()
{
  var strDiv1Cont = $("#first").html();
  var strDiv2Cont = $("#second").html();

  $("#first").html(strDiv2Cont);
  $("#second").html(strDiv1Cont);
}

</script>

Call function interchange on some button click like

<input type ='button' value ='interchange' onclick='interchange' />
Sagar Kadam
  • 487
  • 1
  • 3
  • 10
2

This will do it.

var firstHtml = $('#first').html();
var secondHtml = $('#second').html();

$('#second').html(firstHtml);
$('#first').html(secondHtml);
ZKK
  • 531
  • 3
  • 10