I have two simple select lists and want to add an option to swap values in them. So, there is the first list with e. g. value "ONE" and the other list has value "TWO". When you click "swap" button, the first one should have the value of "TWO" and the second one should have the value "ONE".
Here is jsFiddle: http://jsfiddle.net/YPyRF
Here is the HTML code:
<div class="form-item-from">
<label for="form-item-from">From </label>
<select class="form-select" id="form-item-from"><option value="ONE">ONE</option></select>
</div>
<div class="form-item-to">
<label for="form-item-to">From </label>
<select class="form-select" id="form-item-to"><option value="TWO">TWO</option></select>
</div>
<a href="">Swap values</a>
Here is js code (from Is there a native jQuery function to switch elements?):
jQuery("#form-item-from").after(jQuery("#form-item-to"));
However, this is not working in this case. Additionally, the function shouldn't be dependant on the position of select lists or swap button (I found one solution where the swap button has to be between two lists).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…