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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:54:07+00:00 2026-05-30T15:54:07+00:00

How can I pass custom data to the jQuery event handler, specifically from the

  • 0

How can I pass custom data to the jQuery event handler, specifically from the $(this) element? In HTML5, I probably can legally write:

<a class="delete" href="delete.php?id=5" data-id="5">delete</a>

although I still feel a bit awkard about that. How about prior to that?

$(".delete").click(function() {
   return confirm("Do you really want to delete " + $(this).attr("data-id"));
});

Any best practices?

  • 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-30T15:54:09+00:00Added an answer on May 30, 2026 at 3:54 pm

    you don’t need to use attr()

    jQuery.data() reads html5 data- attributes using data() method which is also a method for storing data objects in an element

    var id=$(this).data('id');
    

    http://api.jquery.com/data/

    As far as only being html 5, lots of bogus attributes have been used for years, browsers typically just ignore them

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

Sidebar

Related Questions

I can write some links: <p>This value is 23456. <a class=edit href=# custom-data=2356>Edit</a></p> <p>This
how can i pass values from my custom components back to the main.mxml? i
I know from here that I can pass an ignore option in the jQuery.validate
How can I pass custom error information from an ASP.NET MVC3 JsonResult method to
MSDN is rather vague regarding this attribute. The custom data string can be set
In ASP.net MVC: How should/Can I pass Form data (From the View) to the
You can pass special strings into jQuery's Datepicker class setDate() method like +7 which
Is there a JavaScript way to pass custom data to a manually created JavaScript
I'm wondering how one can catch and add a custom handler when empty results
I'm trying to pass user input form data jquery/ajax to check if there's any.

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.