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>
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>
Share
Improve this question
asked Feb 27, 2013 at 6:42
OM The EternityOM The Eternity
16.2k44 gold badges125 silver badges187 bronze badges
1
- Possible duplicate: stackoverflow./q/9030322/875127 – Cianan Sims Commented Feb 27, 2013 at 6:45
2 Answers
Reset to default 3Simple 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' />
This will do it.
var firstHtml = $('#first').html();
var secondHtml = $('#second').html();
$('#second').html(firstHtml);
$('#first').html(secondHtml);