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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:45:46+00:00 2026-06-14T20:45:46+00:00

On my page I have $(function() { $(‘.load’).click(function() { var val = $(this).attr(‘value’); //get

  • 0

On my page I have

$(function()
{
  $('.load').click(function()
  { 
  var val =  $(this).attr('value'); //get value of the button that called this function
  //do stuff});
});

and some buttons defined on the initial html:

<input type="button" value="getData1" class="load" />

If I later add more buttons dinamically of the same class, and want them to operate the same way, how can I bind them to the original function?

I was looking at .on but it seems to define a NEW function. I’m hoping there is a way to use the one already defined.

Or should I define the function separately and call it from both places? If so, how can I pass the element that called the function as a parameter?

Any assistance will be much thanked.

  • 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-14T20:45:48+00:00Added an answer on June 14, 2026 at 8:45 pm

    This is what on is for, as you mentioned. On allows you to attach a listener to parts of the document that contain the elements you want to monitor.

    $(document).on('click', '.load', function() { 
        var val =  $(this).attr('value');
    });
    

    Using document isn’t the best, so ideally you would put some selector in there that will match an element that surrounds all of your buttons, current and future.

    Buttons that are added inside document after calling on will also trigger this handler even though they have been added later.

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

Sidebar

Related Questions

I have this function in jQuery that gets data from a page with POST,
I have a page where the visitor initiates a function that executes click() on
in a wordpress page I have this code: function displayData(id) { var $j =
I have function like this: $(document).ready(function () { $(*).click(function () { alert($(this).attr('id').toString()); }); });
On this web page I have a copy function that uses flash swf. I
I have a function that counts the amount of visits a page has, and
I have a function that I use on index.php page and I would like
So I have this function to strip out scripts from the page, but some
I have a page that uses another page via the include() function. The page
I have this script loaded on a page: (function() { window.alert('bookmarklet started'); function AjaxSuccess(data,

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.