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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:09:30+00:00 2026-05-10T22:09:30+00:00

In a previous life, I might have done something like this: <a href=# onclick=f(311);return

  • 0

In a previous life, I might have done something like this:

<a href='#' onclick='f(311);return false;'>Click</a><br/> <a href='#' onclick='f(412);return false;'>Click</a><br/> <a href='#' onclick='f(583);return false;'>Click</a><br/> <a href='#' onclick='f(624);return false;'>Click</a><br/> 

Now with jQuery, I might do something like this:

<a class='clicker' alt='311'>Click</a><br/> <a class='clicker' alt='412'>Click</a><br/> <a class='clicker' alt='583'>Click</a><br/> <a class='clicker' alt='624'>Click</a><br/>  <script language='javascript' type='text/javascript'>     $('.clicker').bind('click', function(e) {         e.preventDefault();         f($(this).attr('alt'));     }); </script> 

Except that using the alt attribute to pass the data from the DOM to jQuery feels like a hack, since that’s not its intended purpose. What’s the best practice here for storing/hiding data in the DOM for jQuery to access?

  • 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. 2026-05-10T22:09:30+00:00Added an answer on May 10, 2026 at 10:09 pm

    JQuery.data lets you associate a dictionary to a DOM element. This data can be set via jQuery:

    <a class='clicker'>Click</a><br/> <a class='clicker'>Click</a><br/> <a class='clicker'>Click</a><br/> <a class='clicker'>Click</a><br/>  <script language='javascript' type='text/javascript'>     var values = new Array('311', '412', '583', '624');     $('.clicker').each(function(i, e) {        $(this).data('value', values[i]).click(function(e) {           f($(this).data('value'));        });     }); </script> 

    or (since jQuery 1.4.3) using the HTML5 data- attributes, which work even in non-HTML5 documents:

    <a class='clicker' data-value='311'>Click</a><br/> <a class='clicker' data-value='412'>Click</a><br/> <a class='clicker' data-value='583'>Click</a><br/> <a class='clicker' data-value='624'>Click</a><br/>  <script language='javascript' type='text/javascript'>     $('.clicker').click(function(e) {         f($(this).data('value'));     }); </script> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Our previous webmaster set up this site and the caching he set up works
In OpenGL, one often writes code like this: glPushMatrix(); // modify the current matrix
EDIT #2 - I'm done the previous state part. Now I need to my
I have a problem with my code that for the life of me I
This is a continuation of one of my previous questions Here are my classes.
I have successfully implemented my GridView now, but, as always, the whole ASP.NET life
I've read the similar posts on this topic, and can't for the life of
Found this recently, but can't for the life of me figure out how the
After reading this nice article (The Care and Feeding of Pre-Compiled Headers), I have
I have have this query which fetches 2 random rows from a database: $query

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.