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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:04:56+00:00 2026-06-15T04:04:56+00:00

I am dynamically loading content into my page using jQuery and Ajax and I

  • 0

I am dynamically loading content into my page using jQuery and Ajax and I would like to attach a Rails link to each object being added. My code to generate the list of data is:

$.each(data.recipients, function(index, object){
    $("#recipient-list").append("<div id=\""+ object.id +"\" class=\"recipient-list-item "+ object.recipient_type +"\">" + object.email + "<br/> </div>");
});

What I want to achieve is add a link_to that will delete the selected item. ie. <%= link_to "Remove", delete_mail_recipient_path(object.id), method: :delete, data: {confirm: "You sure?"} %>

Is it possible to add this code to the page using jQuery or do I need to use html instead? I’ve seen the use escape_javascript used a few places but as far as I can see that is used in js.erb files?

Any help would be appreciated thanks.

  • 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-15T04:04:57+00:00Added an answer on June 15, 2026 at 4:04 am

    So I kinda worked around this using jQuery: here’s my delete code on the jquery side:

    // deletes a mail recipient
    function delete_recipient(element){
        target = element.attr("target");
        var confirm_delete = confirm("Are you sure you want to remove this recipient?")
        if (confirm_delete){
            $.ajax({
                url: '/delete_mail_recipient',
                type: 'delete',
                dataType: 'json',
                data: {
                    id: target
                },
                dataType: 'json',
                success: function(data){
                    if (data.result){
                        console.log(target);
                        $("#"+target).remove();
                    }else{
                        alert("Sorry something went wrong when trying to delete that recipient.");
                    }
                }
            });
        }
    }
    
        // saves the configuration of the mails recipients
        $('#save-config').click(function(){
            var form = $('form#mail-form');
            var valuesToSubmit = $('form#mail-form').serialize();
            console.log(valuesToSubmit);            // 
            save_mail_configuration(valuesToSubmit, form)
        });
    

    And this is the code where I set my id’s for the dynamic objects on the page that I want to be able to remove:

    $.each(data.recipients, function(index, object){
        $("#recipient-list").append("<div id=\""+ object.id + "\" class=\"recipient-list-item "+ object.recipient_type +"\">" + object.email + "<a class=\"remove-recipient\" target=\""+ object.id + "\" > Remove</a><br/> </div>");
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am dynamically loading question content into a div using jquery . This is
I'm using spring-security and jQuery in my application. Main page uses loading content dynamically
I'm dynamically loading content into a div when the user clicks a link using
I'm dynamically loading different content from db, using ajax. So, when I'm loading plain
I'm using jQuery to load some content into a lightbox-like div in a web
On my website, I am loading the content dynamically from database like this e.g
I'm loading content into a fancybox2 and I need it to autosize dynamically after
I am loading a form dynamically into a div. When posting the form using
I am dynamically loading content into my modals, and often it will be a
I'm using a jquery datatable which is loading some JSON dynamically using the sAjaxSource

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.