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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:18:09+00:00 2026-05-27T18:18:09+00:00

I have a query plugin I’m working on and I certain functions after ajax

  • 0

I have a query plugin I’m working on and I certain functions after ajax content has loaded. The problem is that let’s say I re-initiate it 15 times, a click event will then fire 15 times when it’s only clicked once.

Is there a way so it doesn’t keep piling up? I’m calling addToCart onload and also from itemDetail after the ajax return

thanks!

function addToCart()
{
  $(options.add_to_cart).click(function ()
  {
    event.preventDefault();
    var id = $(this).attr('id');

    store_item_id_val = id.replace('store-item-id-', '');
    var quantity = $('.quantity-' + store_item_id_val);

    if (quantity.val() < 1)
    {
      showError('Please enter a quantity of 1 or more.');
      $(quantity).val(1);
      return this;
    }

    $.post($(this).attr('href'),
    { store_item_id: store_item_id_val, quantity: quantity.val() },
      function (data)
      {
        var result = jQuery.parseJSON(data);
        renderCart(result);
      });
  });

  return this;
}

function itemDetails()
{
  $('.item-details').click(function ()
  {
    event.preventDefault();

    var url = $(this).attr('href');

    $.getJSON(url, function (result)
    {

      $('.modal-title').empty().html(result.title);
      $('.modal-content').empty().html(result.html);
      $('#modal').slideDown(100);
      $('.ui-button').button();
      addToCart();
      $('.modal-close').click(function ()
      {
        event.preventDefault();
        $('#modal').hide();
      });
    });
  });
  • 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-27T18:18:10+00:00Added an answer on May 27, 2026 at 6:18 pm

    Based on the code you provided, I would probably say that you have some other code calling itemDetails(). Each time itemDetails() is called, it ADDS another event handler for click to your .item-details. You may want to instead do:

    $(document).ready(function()
    {
      $('.item-details').click(function ()
      {
        event.preventDefault();
    
        var url = $(this).attr('href');
    
        $.getJSON(url, function (result)
        {
    
          $('.modal-title').empty().html(result.title);
          $('.modal-content').empty().html(result.html);
          $('#modal').slideDown(100);
          $('.ui-button').button();
          addToCart();
          $('.modal-close').click(function ()
          {
            event.preventDefault();
            $('#modal').hide();
          });
        });
      });
    });
    

    This would put the event handler on your .item-details classed items, and only fire the events once. If you have dynamic .item-details added and removed you probably should use:

    $('.item-details').live('click', function() ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made my own jQuery plugin, but it has problem that values I
I have a query that is dynamically built after looking up a field list
I have a trip that has many residencies. I need a single query that
I am using in C# MYsql .I have query that works if I run
I've noticed that a few Wordpress blogs have query statistics present in their footer
I have a query that originally looks like this: select c.Id, c.Name, c.CountryCode, c.CustomerNumber,
I have a query that looks like this: public IList<Post> FetchLatestOrders(int pageIndex, int recordCount)
I have a query that I'm executing from a .NET application to a SQL
I have a query that is currently using a correlated subquery to return the
I'm using Jorn Zaefferer's Autocomplete query plugin, http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ I have options set so it

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.