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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:40:11+00:00 2026-06-13T06:40:11+00:00

I have a navigation bar which consists of php-generated html as follows: <ul> <div

  • 0

I have a navigation bar which consists of php-generated html as follows:

<ul>
<div class="container"><button type="button" name="1" class="delButton" alt="Delete"></button></div>
<a href="/" alt="Home">Home</a>
<div class="container"><button type="button" name="2" class="delButton" alt="Delete"></button></div>
<a href="/" alt="Events">Events</a>
<div class="container"><button type="button" name="3" class="delButton" alt="Delete"></button></div>
<a href="/" alt="Calendar">Calendar</a>
<div class="container"><button type="button" name="4" class="delButton" alt="Delete"></button></div>
<a href="/" alt="About Us">About Us</a>
</ul>

Each set consists of a delete button and a link. The name attribute of the button contains the unique id of the link following it, as per the mySQL database.

I’m using the following jQuery code to remove the link when its corresponding delete button is clicked. Note that I’m using a custom ajax() method, and not jQuery’s ajax method.

$('.container button').click(function() {
     if (confirm('Are you sure you wish to remove this link?'))
        ajax('POST', '/deletelink.php', 'id='+this.name, function(xmlhttp) {
           $('.nav ul').load('/getnav.php');
        });
});

The above code works as expected when I click any one of the delete buttons, and it removes the corresponding link. However, if after deleting one link I try clicking on another delete button, nothing happens. The confirm() alert box doesn’t even show up. This suggests that the click() function is not being entered for the second delete attempt.

My interpretation of this is that once the function executes the first time, it resolves the selector to that specific button that was clicked; meaning that subsequently clicking on a different ‘.container button’ is going to have no effect in terms of this function.

Is my assessment correct? If so, is there any way to prevent the function from resolving the selector to the specific object? If not, are there any alternatives that allow me to use one function for all of the delete buttons I have setup now?

  • 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-13T06:40:12+00:00Added an answer on June 13, 2026 at 6:40 am

    Your click handlers are overwritten when you load the getnav.php again. You can use the following construct:

    $(document).on('click', '.container button', function() {
        // click handler code here
    }
    

    You should be able to narrow down the selectors as well:

    $('.nav ul').on('click', '.container button', function() {
        // click handler code here
    }
    

    This binds the click handler on the <ul> itself and then uses the .container button selector to determine where to “send” the click event to.

    See also: .on()

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

Sidebar

Related Questions

I have a view which consists of a tableview and a navigation bar. For
I have an application which have a system add button the navigation bar .on
In my home page template Index.html.twig I have one navigation bar which i only
I have a navigation bar which consists of a <img> elements within their respective
I am an iOS newbie. I have a navigation bar button which when clicked
I have a navigation bar which is an unordered list with tabs as list
Good evening, I would like to have a navigation bar which is centralised to
I have put together a navigation bar which expands a submenu on hover. See
I have a navigation bar that tells the user which page is selected by
I have an app, which has a top navigation bar and a bottom tab

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.