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

  • Home
  • SEARCH
  • 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 8079099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:59:53+00:00 2026-06-05T15:59:53+00:00

I have several HTML elements (buttons) that fire the same JQuery AJAX request. When

  • 0

I have several HTML elements (buttons) that fire the same JQuery AJAX request. When the AJAX request returns successfully, I need to make some updates to the HTML element that triggered the AJAX request. I understand how to do this if I were to hardcode the id of the element to update, such as an item with an id of myDiv as shown in the code below, but I am unsure of how to handle a dynamic id that corresponds to the element that triggered the event.

$('body').on(
    'click',
    '#yt25',
    function(){
        jQuery.ajax({
            'type':'POST',
            'data':$("#custom-hazard-form").serialize()+"&ajaxRequest=hazard-form",
            'success':function(data) {
                $('#myDiv').html('This is the new text'),
            }
            'url':'#',
            'cache':false
     });
    return false;
});

I figure one option is to send the id of the HTML element that triggered the event as a key-value pair in the ajax request ‘data’ option and then have it passed back to the client as part of the AJAX response. I could then grab the id and know which HTML element to update. Is that the best way to handle this or am I missing something more obvious? Thanks.

  • 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-05T15:59:54+00:00Added an answer on June 5, 2026 at 3:59 pm
    $('body').on(
    'click',
    '#yt25',
    function(){
        var _this = this;
        jQuery.ajax({
            'type':'POST',
            'data':$("#custom-hazard-form").serialize()+"&ajaxRequest=hazard-form",
            'success':function(data) {
                $(_this).html('This is the new text'),
            }
            'url':'#',
            'cache':false
     });
    return false;
    });
    

    You don’t need to sent it along with the ajax request.
    This is one variation. You can also do this be assinging some classes to the element and get those elements by that class will do.

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

Sidebar

Related Questions

I have a HTML form where I use several buttons. The problem is that
i have several common elements (components), that will generate some html. it seems my
I have several same HTML elements going one after another: <span>1</span> <span>2</span> <span>3</span> I'm
I have the following Jquery Ajax call that upon completion changes the HTML of
I have html that looks like this with several items <div class=item> <p class=price>$388.00</p>
I have some ajax requests associated with several elements on my page - when
I have an HTML form spread across several divs. I need to know when
I have a site that uses for example html element id=some_id several times and
I have several html input elements which all look something like this: <input id=1
In an intranet app I have HTML elements with custom tags. There are several

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.