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

Most of my development life, I have done a JavaScript generated button like so:
There is previous little on the google on this subject other than people asking
In OpenGL, one often writes code like this: glPushMatrix(); // modify the current matrix
I worked with StreamBase in a previous life, and found it to be very
This is basically a follow up question to my previous question found here I'm
So i have this very basic ipad view controller and i was doing some
I've read the similar posts on this topic, and can't for the life of
In previous releases there were 3 ways to pass data from controller to view
In previous versions of jQuery tabs there was an option to automatically set the
In a previous Git question , Daniel Benamy was talking about a workflow in

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.