admin管理员组文章数量:1415673
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);
本文标签:
版权声明:本文标题:javascript - How to interchange two <div> position in HTML using jquery on selection of any dropdown value? - Stac 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745224576a2648546.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论