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

  • Home
  • SEARCH
  • 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 6075053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:27:04+00:00 2026-05-23T10:27:04+00:00

I am building app with php and jquery and it has many ajax loads

  • 0

I am building app with php and jquery and it has many ajax loads and functionalities. What i would like to know is what is the most widely used and acceptable way of accessing dom elements with jquery and adding events to it using jquery and javascript and if there is any rule of thumb to follow for the following instances.(and how i do them now)

A query generates a list of records and each record has to be edited and deleted.

The generated records look like this

<a href="javascript:;" class="edit" id="edit-id-300" alt="edit-type-1">Record1</a>
<a href="javascript:;" class="delete" id="delete-id-300" alt="delete-type-1">Record1</a>
<a href="javascript:;" class="edit" id="edit-id-301" alt="edit-type-1">Record2</a>
<a href="javascript:;" class="delete" id="delete-id-301" alt="delete-type-1">Record2</a>
<a href="javascript:;" class="edit" id="edit-id-302" alt="edit-type-2">Record3</a>
<a href="javascript:;" class="delete" id="delete-id-302" alt="delete-type-2">Record3</a>

and my jquery code handle them would be

$(".edit").click(function() {
    var currentElementId = $(this).attr("id").replace("edit-id-","");
    $("#ajaxdiv").load("ajaxpage.php","editid="+currentElementId);
});

is this type of stuff ok? i mean is there any other way to do stuff like this especially when this gets more complicated like have to add 3 more identifiers to id and then exploding them and finding out each of the identifiers separately. Any guidelines here to follow.?

  • 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-05-23T10:27:05+00:00Added an answer on May 23, 2026 at 10:27 am

    If you simply need to have something that can be cleaner, maybe you can consider bind the record into one
    meaningful div, and use .live() to bind the event handlers
    i.e.,

    <div data-rec-id = '300'>
        ...
        <span class='link del' data-act='del'>Delete</span>
        <span class='link edit' data-act='edit'>Edit</span>
    </div>
    <div data-rec-id = '301'>
        ...
        <span class='link del' data-act='del'>Delete</span>
        <span class='link edit' data-act='edit'>Edit</span>
    </div>
    
    $('.edit').live('click', function(){
        var id = $(this).closest('[data-rec-id]').attr('data-rec-id');
        $("#ajaxdiv").load("ajaxpage.php","editid="+id);
    });
    

    or even generic:

    $('.link').live('click', function(){
        var id = $(this).closest('[data-rec-id]').attr('data-rec-id');
        var action = $(this).attr('data-act');
        $("#ajaxdiv").load("ajaxpage.php","id="+id+"&act="+action);
    });
    

    Please don’t use something like:

    <a href="javascript:;" ...
    

    or I would suggest you use some robust framework. e.g., http://documentcloud.github.com/backbone/

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

Sidebar

Related Questions

Im building a codeigniter app which uses json_encode to provide ajax data in many
I'm building a web app and would like to use an ORM to map
I'm building a web app with PHP and Python (The site has SSL) and
I'm building an app in PHP and I'm using the data mapper pattern for
I'm building a small web app in PHP that stores some information in a
I'm building a PHP calendar app for a photography group. They need to be
I'm building an app that authors would (hopefully) use to help them, uh.. author
We're building a PHP app based on Good old codeigniter framework and have run
My PHP app has a number-crunching part that is just to slow for PHP,
I building a simple, 7 page, database driven, website, and I would like to

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.