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

This seems like such a trivial thing but I can’t for the life of
Sorry, this might be duplicated, I'm not sure if my previous attempt to post
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
From the Xerces2 Java Parser Readme page ,Changes from Previous Release section: This release
This is a continuation of one of my previous questions Here are my classes.
I'm confident that this is possible but for the life of me I can't
I have successfully implemented my GridView now, but, as always, the whole ASP.NET life
Hello i dont know if this is related to a previous question that i

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.