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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:04:48+00:00 2026-06-10T15:04:48+00:00

I can’t seem to make the code below work after an initial successful click.

  • 0

I can’t seem to make the code below work after an initial successful click. I tried both $.post and ajax to no avail. The initial click to delete any of the items work, but the succeeding clicks do not work

<script>    
$(document).ready(function(){
$('[id^="del"]').click(function(){
    var valname = $(this).attr('id').split('del_');
    /*$.post("delthis.php", {id: ""+valname[1]+""}, function(data) {
            $("#dynamic_section").html(data);
    });*/
    $("#dynamic_section").load('delthis.php', {"id":valname[1]} );
    return false;
  });
});
</script>

<body>

<div id='static_section'>This is the static section</div>
<div id='dynamic_section' style='border: 1px solid black;'>
<?php
// db connection here
$sql = mysql_query("SELECT * from test_table ORDER BY id");
while ($row = mysql_fetch_array($sql))
{
?>
<p><a href='#' id='del_<?php echo $row['id']; ?>'>Hello <?php echo $row['id']; ?></a></p>
<?php
} 
?>
</div>

This is the simple delthis.php file:

<?php
// db connection 
//$id = $_POST['id'];
$id = $_REQUEST['id'];

$sql = mysql_query("DELETE from test_table WHERE id = '$id'");

$sql = mysql_query("SELECT * from test_table ORDER BY id");
while ($row = mysql_fetch_array($sql))
   $html .= '<p><a href="#" id="del_' . $row['id'] . '">Hello ' . $row['id'] . '</a></p>';

echo $html;

?>

Appreciate any help/pointers. TIA!

  • 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-06-10T15:04:50+00:00Added an answer on June 10, 2026 at 3:04 pm

    The problem is that you replace all the content of the #dynamic_section so you have to “re-bind” the click event. Try this.

    <script>    
    $(document).ready(function(){
        function doPost(evt) {
            evt.preventDefault();
            var valname = $(this).attr('id').split('del_');
            $.post("delthis.php", {id: ""+valname[1]+""}, function(data) {
                $("#dynamic_section").html(data);
                $('[id^="del"]').click(doPost);
            });
        }
    
        $('[id^="del"]').click(doPost);
    });
    </script>
    

    Good luck!

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

Sidebar

Related Questions

Can't seem to figure out what's wrong with the simple getJSON call below. It's
Can't work out a way to make an array of buttons in android. This
Can someone thoroughly explain the last line of the following code: def myMethod(self): #
can someone explain why the compiler accepts only this code template<typename L, size_t offset,
Can someone please explain why this doesn't work? MyClass myClass1 = new MyClass(); object
Can some one Guide me to work with these things... What is Model popup
can anyone tell me why this doesn't work? db = openOrCreateDatabase(database.db, SQLiteDatabase.CREATE_IF_NECESSARY, null); db.setLocale(Locale.getDefault());
Can any one post the details to develop restful web service in .net from
Does anyone know how can I replace this 2 symbol below from the string
Can i get the source code for a WAMP stack installer somewhere? Any help

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.