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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:29:35+00:00 2026-05-31T01:29:35+00:00

$.each(data, function(i,data) { …[cut]… +<a id=\contact_+data.id+_delete\ href=\/user/contact/delete/ticket_id/+data.ticket_id+/contact_id/+data.id+\>Delete</a> …[cut]… $(#contact_+data.id+_delete).live(‘click’,function() { var href = this.attr(‘href’);

  • 0
$.each(data, function(i,data) {
...[cut]...
    +"<a id=\"contact_"+data.id+"_delete\" href=\"/user/contact/delete/ticket_id/"+data.ticket_id+"/contact_id/"+data.id+"\">Delete</a>"
...[cut]...
    $("#contact_"+data.id+"_delete").live('click',function() {
        var href = this.attr('href');
        alert(href);
        return false;
    });

I have the following code sample (irrelevant parts cut out for simplicity). What I have is a function that redraws the rows (tr’s) of a table. Each row has a ‘delete’ link at the end of the row that calls a url /user/contact/delete/ticket_id/{$ticket_id}

Then (within the same loop), I want to bind a click event to the newly created link. However when I click the link, the browser leaves the page and goes to the url rather than going to the clicked link function.

First, am I binding the click event properly?

Second, am I retrieving the ‘href’ attribute of the element correctly?

  • 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-31T01:29:36+00:00Added an answer on May 31, 2026 at 1:29 am

    In addition to what @charlietfl says, you could have a single handler for all of your delete elements. Simply add the same class to all of them, like class="contact_delete", and then use .on() to target all of them:

    +'<a class="contact_delete" id="contact_'+data.id+'_delete" ...
    

    Note that if you use single quotes, you don’t have to escape all of your double-quotes.

    $('body').on('click', '.contact_delete', function() {
        var href = $(this).attr('href');
        alert(href);
        return false;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: $.getJSON(Featured/getEvents, function(data){ $.each(data.events, function(i,event){ var title = event.title.substr(0,20); $(#title-+i).text(Text); if
var list = []; $.getJSON(json.js, function(data) { $.each(data, function(i, item) { console.log(item.text); list.push(item.text); });
$.get(CallBack.aspx, { nm: StateTx, nm2: StateTx2 }, function(data) { $.each(data, function() { $('[id$=DropDown1]').append(<option value=
The code: function updateDashboardData() { $.getJSON(includes/system/ajaxDataInterface.php, {recordcount:1}, function(data) { $('.stationContainer').each(function(data) { var bsID =
I'm using this code $.post(assets/scripts/chat/load_convos.php,{}, function(data) { $.each(data, function(index, value) { alert(value); }); ,and
Here is my Javascript: $.post('foo.php', { request: Request }, function(data) { $.each(data.chats, function(i, chat)
Let's say I have the following javascript: (function($) { $.getJSON(url, function(data) { $.each(data.rows, function(index,
$.ajax seems to be broken for me: $.ajax({url:'getGalleries.php', datatype:'jsonp', success: function(data){ $('#galleries').html(''); $.each(data,function(key,value) {
$.each(json.data,function(i,fb){ //some code here... if (msg.length > 150) { msg = msg.substr(0,200)+...; } //more
I have got this far with my coding: success: function(data) { $.each(data, function(item){ if

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.