Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6191245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:43:48+00:00 2026-05-24T02:43:48+00:00

i am trying to remove the div old image and append a new one

  • 0

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

$(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('<img src="color/color1.jpg">');
            break;
             case 'color2':
             $("#div1 img:last-child").remove();
               $('#div1').append('<img src="color/color2.jpg">');
             break;
            case 'color3':
             $("#div1 img:last-child").remove();
               $('#div1').append('<img src="color/color3.jpg">');
           break;
        }

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

 });

html code::

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

<form method="post" action="step3.php">    
    <div id="div1" >
        <?php if(isset($_SESSION['img'])){
            echo '<img src="' . $_SESSION['img'] . '" >' ;
        } ?>
        <input name="color" type="text" value="" id="hiddenimg" />
        <input name="submit" type="submit" value="Submit" />
    </div>
</form>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:43:49+00:00Added an answer on May 24, 2026 at 2:43 am

    you can try the jQuery :last selector: link

    for you need something like:

    $("#div1 img:last").remove();
    

    or a better version

    $("#div1 img").filter(":last").remove();
    

    I don’t know to test right now, I hope this is your working solution 🙂

    (Sorry for my english :”> )

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to remove the last character from a div id using jQuery.
jsFiddle I'm trying to remove the border of a div using jQuery, but it's
I'm trying to remove all but the first child component from a Java Container.
am trying to remove a div inserted by jquery onclick. for some reason its
I'm trying to remove a few rows surrounded by a div, but it doesn't
I'm trying to remove the image border in ie, but I get some strange
I am trying to remove the first wrapping tag of an image IF one
i am trying to remove parent tag, but removing parent tag should not remove
I am trying to remove a division but I am not able to remove
I am trying to remove this div <div id=myid class=myclass>other_tags_here</div> I am using preg_replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.