What is a cool way to apply this? I need a script that exchange two < li>'s position in an < ul>. It think that should be possible to achieve. Thanks for your response.
HTML
<div id="awesome">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
</div>
Pseudo Javascript (JQuery)
$("#awesome ul li:eq(1)").exchangePostionWith("#awesome ul li:eq(3)");
HTML Result
<div id="awesome">
<ul>
<li>Item 1</li>
<li>Item 4</li>
<li>Item 3</li>
<li>Item 2</li>
<li>Item 5</li>
</ul>
</div>
You can use jQuery's
.after()
for moving elements around. I cloned one of them so the original can remain as a placeholder. It's like if you wanted to switch variablesa
andb
, you'd need a third temporary variable.Now your pseudocode
$("#awesome ul li:eq(1)").exchangePositionWith("#awesome ul li:eq(3)");
isn't so pseudo :-)I was needing the same and I made an example, check it here http://jsfiddle.net/jeduarz/f88u9u9p/1/
HTML:
CSS:
JS (with jQuery):