i'm trying to change the position of two DIV'S in jquery, it seems that i may be a little confuse because it is already swapping position, but when it do, it duplicates the field.
i tried using insertBefore and insertAfter.
<div id="before_stops">
<li><span><img src="<?php echo base_url('assets/images/multi_stops.png') ?>" width="18px"height="18px"/></span>
<div class="verticalLine"></div>
<span class="text multi_non_append_stops"></span>
<br><br>
</li>
</div>
<div id="multi_stops">
<span class="text multi">
<li><span>
<img src="<?php echo base_url('assets/images/EndPoint.png')?>" width="18px" height="18px"></span>
<div class="verticalLine"></div>
<br/><br>
</li>
</span>
</div>
Here is my javascript code:
for (var i = 0; i < data.stops.length; i++) {
if(value == "A" || value == "B"){
$('#multi_stops').insertBefore($('#before_stops'));
$('.multi').append('<li><span><img src="' + base_url + 'assets/images/multi_stops.png" width="18px" height="18px"></span><div class="verticalLine"></div>' + data.stops[i].stopDestination + "<br/><br></li>");
}else{
$('#multi_stops').insertAfter($('#before_stops'));
$('.multi').append('<li><span><img src="' + base_url + 'assets/images/multi_stops.png" width="18px" height="18px"></span><div class="verticalLine"></div>' + data.stops[i].stopDestination + "<br/><br></li>");
}
}
what is happening is instead of having a output of
if the value is A
or B
it should be
<div id ="multi_stops"></div>
<div id ="before_stops"><div>
but what is happening to me is
<div id ="multi_stops"></div>
<div id ="before_stops"><div>
<div id ="multi_stops"></div>
else if the value is not A
or B
it should only be
<div id ="before_stops"></div>
<div id ="multi_stops"><div>
but what is happening is
<div id ="before_stops"></div>
<div id ="multi_stops"><div>
<div id ="multi_stops"></div>
it is duplicating. what am i doing wrong here.