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 7645785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:01:58+00:00 2026-05-31T10:01:58+00:00

I have a php page where I add and delete items from database using

  • 0

I have a php page where I add and delete items from database using Jquery + PHP + AJAX.

Now I am able to delete and add when that page loads for the first time.

Now if I first add an element; which in turn adds record to the DB and then updates the div that contains all the listing of divs.
Example:

<div id="all_items">
  <div id= "item_1">
      <a id="delete_link">...</a>
  </div>
  <div id= "item_2">
      <a id="delete_link">...</a>
  </div>
  .... Upto Item n
</div>

Now I replace the div with id all_items.

Now I have jQuery at the bottom of the page which calls ajax on a tag of delete_link.

Situtation is:

When page is loaded I can delete any item from the list.
But if I page load i add new item first. (which will update all_items div) after that if I try to click on delete link. Jquery on click selector event is not fired and which in turn doesn’t do delete ajax operation.

I couldn’t figure out why this is happening.

Looking for some help here.

EDITED:
Sorry for not writing code earliar.
Following is the jQuery I am talking about.

    <script type="text/javascript" >
    var jQ = jQuery.noConflict();
    jQ(function() {
                jQ("#submit_store").click(function() {
                            var store_name = jQ("#store_name").val();
                            var dataString = 'store_name='+ store_name;
                            dataString += '&mode=insert';
                            if(store_name =='')
                            {
                                        alert("Please Enter store Name");
                            }
                            else {
                                    jQ.ajax({
                                                type: "POST",
                                                url: "<?php echo $mycom_url; ?>/store_insert.php",
                                                data: dataString,
                                                cache: false,
                                                success: function(html){
                                                            jQ("#dvstoreslists").html(html);                                                            
                                                            document.getElementById('store_name').value='';
                                                            document.getElementById('store_name').focus();
                                                }
                                    });
                        }

                        return false;
            });

            jQ(".store_delete").click(function() {
                        var store_id = jQ(this).attr('id');

                        var id = store_id.split("_");
                        var dataString = 'store_id='+ id[2];
                        dataString += '&mode=delete';
                        var to_delete = "#store_list_" + id[2]
                                    jQ.ajax({
                                                type: "POST",
                                                url: "<?php echo $mycom_url; ?>/store_insert.php",
                                                data: dataString,
                                                cache: false,
                                                success: function(html){
                                                            jQ(to_delete).hide("slow");
                                                }
                                    });
                        return false;
            });
});

</script>

So If on page load, I delete then delete on click jquery event is fired. But after adding new store and replacing div of stores with new div. then jQuery on click event is not fired.
My HTML is as below.

    <div class="sbBox stores">
        <form id="add_storefrm" name="add_storefrm" method="post" action="" >
            <div class="dvAddStore">
                <div class="dvName" id="store_list">
                    <input type="text" id="store_name" name="store_name">
                    <input type="hidden" value="addstore" id="mode" name="mode">        
                </div>

                <div class="btnAddStore">
                    <input type="submit" name="submit_store" value="Add Store" id="submit_store">
               </div>
           </div>
           <div id="dvstoreslists">
               <?php
               $query = "SELECT * FROM #__shoppingstore order by store_id desc;";
               $db->setQuery($query);
               $rows = $db->loadObjectList();
               foreach($rows as $row)
               {
                   echo "<div class=dvlist id=store_list_".$row->store_id ."><div class=dvStoreListLeft>";
                   echo "<div class='slname'><h3>" . $row->store_name . "</h3></div>";
               ?>
               <div class="slDelBtn">
                   <p id = "p_store_<?php echo $row->store_id ; ?>">
                       <a id="store_delete_<?php echo $row->store_id ; ?>" class="store_delete" alt="Delete" onclick="DeleteStore(<?php echo $row->store_id ; ?>);" >            
                       </a>
                   </p>
               </div>
           </div>
       </div>
       <?php   } ?>
   </div>
   </form>
   </div>

Sorry folks for not posting the code earliar.

  • 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-31T10:02:00+00:00Added an answer on May 31, 2026 at 10:02 am

    When you replace the contents of #all_items any event handlers that were bound to any descendants will no longer exist. You can use event delegation, using the on method, to solve this:

    $("#all_items").on("click", ".delete_link", function() {
        //Do stuff
    });
    

    Notice that I’m using a class selector (.delete_link) instead of an ID selector for the links. It’s invalid to have duplicate IDs in the same document.

    Also note that the above will only work if you are using jQuery 1.7 or above. For older versions, use delegate instead:

    $("#all_items").on(".delete_link", "click", function() {
        //Do stuff
    });
    

    This works because DOM events bubble up the tree from their target. So a click on a link which is a descendant of #all_items will bubble up through all of its ancestors and can be captured when it reached #all_items.

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

Sidebar

Related Questions

I have a php page that displays rows from a mysql db as a
I have a PHP page, in Wordpress. When I add a inline Thickbox to
I have a PHP page that returns a piece of HTML to set the
I have a PHP page that I run every minute through a CRON job.
I have a PHP page that does a couple of different things depending on
I have a php page that takes in a bunch of url parameters and
I have a page where i add,edit and delete menus.For add and edit I
I have a PHP / Javascript page that automatically logs a user into different
i have a php page where i am listing all usernames from db to
I have a simple cart page that displays items that are in someones cart,

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.