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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:59:06+00:00 2026-06-17T20:59:06+00:00

I am totally shocked when I found that jquery can get value from any

  • 0

I am totally shocked when I found that jquery can get value from any randomly defined attribute.

HTML

<a postid='10' class='delete_post'>Delete</a>

JS

$('body').on('click', '.delete_post', function() {
    var id = $(this).attr('postid');
    delete_post(id); //$.post request for deleting post
});

I made fiddle here for testing this.

My question here is => Is it advisable to use such randomly defined attributes to get value?

Generally I get value using below code.

HTML

<div class='delete_post'>
    <a>Delete</a>
    <input type='hidden' class='id' value='10' />
</div>

JS

$('.delete_post').on('click', 'a', function() {
    var id = $(this).parent().find('.id').val();
    delete_post(id); //$.post request for deleting post
});

(I tested this successfully in chrome, firefox and internet explorer.)

  • 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-06-17T20:59:07+00:00Added an answer on June 17, 2026 at 8:59 pm

    Although this will generally work, it is not advisable to use proprietary/user-defined attributes. These will not validate and there is the possibility of you incorrectly using a real attribute. Your code is also not future-proof in that you may define an attribute that is not used now, but could be used later.

    Instead, you should use data- attributes / .data:

    <input data-postid=10 class=delete_post>
    
    var postID = $(this).data('postid');
    

    Spec: http://www.w3.org/TR/2011/WD-html5-20110525/elements.html#embedding-custom-non-visible-data-with-the-data-attributes

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

Sidebar

Related Questions

I totally can't get my head around writing a correct query for my problem
I am totally stuck here and found tens of samples on posting to get
Totally new to Capistrano. I have a local git repository that I want to
Totally confused here. I have a PARENT UIViewController that needs to pass an NSMutableArray
im totally new when it comes to trying to make HTML code. I was
I'm totally new to this WCF Services thing so any guidelines would be greatly
I´m totally new to Powershell and wanted to write a script that deletes all
sadly i am totally new to jquery-writing and after googling for 12 hours to
i'm totally bugged from this problem... i need to know how to rewrite this
Seems totally backward to me that such an excellent IDE would hide line numbers

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.