I want to be able to change ID when moving the div up and down so then I can submit them numbers to MySQLi...
So basically from
<div id="1" class='col1'>1</div>
<div id="2" class='col2'>2</div>
<div id="3" class='col3'>3</div>
<div id="4" class='col4'>4</div>
<div id="5" class='col5'>5</div>
to
<div id="5" class='col1'>1</div>
<div id="2" class='col2'>2</div>
<div id="4" class='col3'>3</div>
<div id="1" class='col4'>4</div>
<div id="3" class='col5'>5</div>
or something like that...
HTML
<div id='items'>
<div id="1" class='col1'>1</div>
<div id="2" class='col2'>2</div>
<div id="3" class='col3'>3</div>
<div id="4" class='col4'>4</div>
<div id="5" class='col5'>5</div>
</div>
<a href="#" id="up">Up</a>
<a href="#" id="down">Down</a>
JS
$(document).ready(function(){
var selected=0;
var itemlist = $('#items');
var len=$(itemlist).children().length;
$("#items div").click(function(){
selected= $(this).index();
alert("Selected item is " + $(this).text());
});
$("#up").click(function(e){
e.preventDefault();
if(selected>0)
{
jQuery($(itemlist).children().eq(selected-1)).before(jQuery($(itemlist).children().eq(selected)));
selected=selected-1;
}
});
$("#down").click(function(e){
e.preventDefault();
if(selected < len)
{
jQuery($(itemlist).children().eq(selected+1)).after(jQuery($(itemlist).children().eq(selected)));
selected=selected+1;
}
});
});
CSS
#items div{
width:100px;
height:20px;
border:1px solid #000;
margin-top:2px;
text-align:center
}
div .col1{
background-color:#000;
color:#fff
}
.col2{
background-color:#0f0;
}
.col3{
background-color:#00f;
color:#fff
}
.col4{
background-color:#f00;
color:#fff
}
.col5{
background-color:#ff0;
}
Everything moves but somehow I need it to change the ID if possible so then it will sort in that order.
Is this possible? If so can someone help me please.