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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:52:58+00:00 2026-05-27T00:52:58+00:00

I have a table of buttons that are printed using PHP. Each button has

  • 0

I have a table of buttons that are printed using PHP. Each button has a different value in its data attribute but does the same thing. I want the value of the data attribute of a particular button’s data attribute. This does not work:

$(this).find('button').data('myatt')

The above returns the first button’s data attribute value rather than the one the user clicked.

EDIT: jsfiddle to illustrate: http://jsfiddle.net/7fkfu/17/

Any ideas? Thank you :).

  • 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-27T00:52:58+00:00Added an answer on May 27, 2026 at 12:52 am

    OK, the problem is in how you were trying to use the .on method: you were trying to say on().click(), but you don’t want both. The first param to .on() is a string indicatingthe event(s) you want to handle. Then a selector, an optional data param, and then last you put the actual handler. (There’s also an events-map format – see the .on() doco.) Also in the fiddle it was checking for buttons with [rel=modal] but in the html it was rel=test. Try the following:

    $(function() {
      $('#mytable').on('click','tr button[rel=test]',function() {
         alert($(this).data('mydata'));
      });
    });
    

    An updated fiddle that works: http://jsfiddle.net/7fkfu/19/

    Also, don’t create more than one element with the same ID. (Doesn’t affect your code in this case, but really it is invalid HTML and if you actually try to select elements by ID it will matter.)

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

Sidebar

Related Questions

I have multiple table rows that has a set of radio buttons on each
I have a table containing images and buttons. Each button has a tag with
I have a big table containing a button in each cell. These buttons are
I have a table of radio buttons that have an ID value that contains
In main.xml, I have a table layout that it has two buttons in the
I have a table full of radio buttons. Each one has a name and
Using this as a simplified example, assume I have a table that has some
In this jsfiddle http://jsfiddle.net/littlesandra88/eGRRb/ have I submit buttons that are auto-generated. Each table row
I've got a gridview that renders as a table. I have an Add button
I have a table (in a form) populated with radio buttons (with a button

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.