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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:56:01+00:00 2026-06-13T14:56:01+00:00

I have a bunch of elements, and I want to set a click handler

  • 0

I have a bunch of elements, and I want to set a click handler for all of them, and then do something based on which one was clicked. For the example you can just have it give an alert stating the class of the button that was clicked. My elements look like this: <input type="button" class="numpad np-txtTP"> and they are all contained in the same element. In my case I want to take whatever is after np-txt and add it to a textbox.

  • 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-13T14:56:02+00:00Added an answer on June 13, 2026 at 2:56 pm
    var container = document.getElementById('container');
    var elements = container.getElementsByTagName('input');
    for(i = 0; i < elements.length; i++){
        elements(i).addEventListener('click', function() {
            alert(this.className);
        });
    }
    

    will assign a click handler to all input elements within an element of id container that will alert their classname


    This can also easily be done in jQuery in the following way if you have access to it

    $(function() {
        $('input[type=button]').click(function() {
            alert($(this).prop('class'));
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of < li > elements which I want to animate
I have a bunch of li elements that I want to alternate in color
I have a bunch of a elements and I want to add a GET
I have TextBox and ListBox with bunch of elements. TextBox has KeyDown event handler,
I have a bunch of indexes and I want to remove elements at these
I have a bunch of forms that have various input elements. I want to
I have a bunch of forms that have various input elements. I want to
I have a bunch of <div> elements, each of which has a name .
I have a bunch of LI elements for which I need to change the
I have a bunch of divs that are all hidden like this <div class=elements>

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.