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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:43:42+00:00 2026-06-17T18:43:42+00:00

There is given code: <div id=256> <p>SOMELEMENT</p> <button class=edit>EDIT</button> <button class=delete>DELETE</button> </div> <div id=257>

  • 0

There is given code:

<div id="256">
   <p>SOMELEMENT</p>
   <button class="edit">EDIT</button>
   <button class="delete">DELETE</button>
</div>
<div id="257">
   <p>SOMELEMENT2</p>
   <button class="edit">EDIT</button>
   <button class="delete">DELETE</button>
</div>
<script>
   $(".edit").click(function() { var id = $(this).parent().attr("id"); /* do some Ajax here, edit element in database with given id*/});
   $(".delete").click(function() { var id = $(this).parent().attr("id"); /* do some Ajax here, delete element in database with given id*/});
</script>

There is a database with some elements, these elements have ID and I would like to do some actions on these elements via Ajax. I need database ID of element so that I can do some Ajax requests on this element. Solution above works, however there are some flaws – it is dependent from HTML structure (for example when I wrap button with some other element then parent() will not work because HTML structure changed).

How to store the better way database IDs of elements in HTML so JavaScript can get it for example for Ajax requests?

  • 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-17T18:43:43+00:00Added an answer on June 17, 2026 at 6:43 pm

    Why not do something like this using the data() method:

    <div>
       <p>SOMELEMENT</p>
       <button class="edit" data-id="256">EDIT</button>
       <button class="delete" data-id="256">DELETE</button>
    </div>
    <div>
       <p>SOMELEMENT2</p>
       <button class="edit" data-id="257">EDIT</button>
       <button class="delete" data-id="257">DELETE</button>
    </div>
    

    Now that you have the data-id associated with your buttons, you can do:

    $(".edit").click(function() { 
      var id = $(this).data("id"); 
      /* do some Ajax here, edit element in database with given id*/
    });
    

    EXAMPLE

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

Sidebar

Related Questions

Given the following sample form code and CSS stylesheet Form <div class="Center_300 "> <button
Given the following code, is there a way I can call class A's version
Given the following code <div class=container> <p>Some Text</p> <p><img src=image.jpg><p> <p>More Text</p> </div> CSS
Is there a built in Java code that will parse a given folder and
Given the following php code... <?php exec('myscript.php'); exec('finish.php'); ?> Is there a way to
In my below given code, the second DIV section is not executing. The PHP
I have a DIV element with this given class: .slideshow { background: white; width:
Is there any available C++ (or maybe C) function/class/library with only purpose to sanitize
All, I am studying some sample code given in my web dev class as
There are two sets of javascript SDK code, the one given on the SDK

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.