Why Remove last child does not work?
<p>i am trying to remove the div old image and append a new one using last child(jQuery) but it does not work i get a new image appended beside the old one.
here is jQuery code</p>

<pre><code>$(function() {

$('.iconWrapper span').click(function(e){
 var kleur=$(this).attr('class');
        switch(kleur){
            case 'color1':
             $("#div1 img:last-child").remove();
             alert($("#div1").html());
               $('#div1').append('&lt;img src="color/color1.jpg"&gt;');
            break;
             case 'color2':
             $("#div1 img:last-child").remove();
               $('#div1').append('&lt;img src="color/color2.jpg"&gt;');
             break;
            case 'color3':
             $("#div1 img:last-child").remove();
               $('#div1').append('&lt;img src="color/color3.jpg"&gt;');
           break;
        }

        $('#hiddenimg').val(kleur);
    e.preventDefault(); 

 });
</code></pre>

<p>html code::</p>

<pre><code>&lt;?php
error_reporting('E_ALL');
ini_set('display_errors', 1);
session_start();
$img=$_POST['img'];
$_SESSION['img']=$img;
?&gt;
&lt;div class="iconWrapper"&gt;
    &lt;ul class="color"&gt;
        &lt;li&gt;
            &lt;a href="#" title="Selecteer"&gt;&lt;span class="color1"&gt;&lt;/span&gt;&lt;/a&gt;                               
        &lt;/li&gt;
        &lt;li&gt;
            &lt;a href="#" title="Selecteer "&gt;&lt;span class="color2" &gt;&lt;/span&gt;&lt;/a&gt;                               
        &lt;/li&gt;
        &lt;li&gt;
            &lt;a href="#" title="Selecteer"&gt;&lt;span class="color3"&gt;&lt;/span&gt;&lt;/a&gt;                               
        &lt;/li&gt;
        &lt;li&gt;
            &lt;a href="#" title="Selecteer"&gt;&lt;span class="color4"&gt;&lt;/span&gt;&lt;/a&gt;                               
        &lt;/li&gt;
    &lt;/ul&gt;
&lt;/div&gt;

&lt;form method="post" action="step3.php"&gt;    
    &lt;div id="div1" &gt;
        &lt;?php if(isset($_SESSION['img'])){
            echo '&lt;img src="' . $_SESSION['img'] . '" &gt;' ;
        } ?&gt;
        &lt;input name="color" type="text" value="" id="hiddenimg" /&gt;
        &lt;input name="submit" type="submit" value="Submit" /&gt;
    &lt;/div&gt;
&lt;/form&gt;
</code></pre>
