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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:55:21+00:00 2026-05-31T18:55:21+00:00

I’m trying to add a li to a list with jquery. When the user

  • 0

I’m trying to add a li to a list with jquery. When the user accepts a pending invitation, the invitation’s status is set to confirmed in the db, it is deleted from the “pending invitations” list on the page, and it appears in a separate UL below. All of this is working fine except the link in the newly-created li does not work. Or, rather, it works in terms of the deleting the item from the database, but it does not disappear from the screen. If I reload the page, it is gone. Here’s my code:

teams_controller.erb:

      def myteams
    action = params[:command]

    if (action == "accept")
      @invite = TeamUser.find(params[:id])
      @invite.confirmed = true
      @invite.save
      @newteam = @invite
    end

    if (action == "delete")
      @invite = TeamUser.find(params[:id])
      @team = Team.find(@invite.team_id)
      @invite.destroy
      if (@team.owner == current_user.id)
        @team.destroy
      end

    end

    @teams = current_user.teams

    respond_to do |format|
      format.html 
      format.js
      format.json { head :ok }
    end
  end

myteams.js.erb:

$('#<%= dom_id(@invite) %>').fadeOut(700);
<% if @newteam %>
 $('#acceptedList').append("<%= escape_javascript(render :partial => 'teaminlist', :locals => {:invite => @newteam})%>");
<% end %>

_teaminlist.html.erb:

<li class='team' id='<%= dom_id(invite) %>' >
  <h3>
  <% if invite.team.owner == current_user.id%><i><% end %>
  <%=link_to invite.team.name, 
          :controller => 'teams', :action => 'show', :id => invite.team.id %></i>
  <%=link_to image_tag('delete.png'), 
          {:controller => 'teams', :action => 'myteams', :id => invite.id, :command => 'delete'},
          :class => 'deleteTeam', :remote => true %>
</h3></li>

myteams.html.erb:

<h3>My Teams</h3>
<p id="notice"><%= notice %></p>


<p style='clear:both'></p><hr width='660'><BR>

<div class="post">
<h3 style="text-decoration:underline;">Pending Invitations:</h3>
<ul style="list-style-type:none; line-height:20pt;" id='inviteList'>
<% current_user.team_users.where("confirmed is null").order("created_at DESC").each do |invite|%>
  <li class='invite' id="<%= dom_id(invite) %>">
  <h3><%=link_to invite.team.name,
          :controller => "teams", :action => "show", :id => invite.team_id %>
  <%=link_to image_tag("checked.png", :size => "16x16"), 
          {:controller => "teams", :action => "myteams", :id =>invite.id, :command => "accept"}, 
          :class => "deleteTeam", :remote => true %>
  <%=link_to image_tag("delete.png"),
          {:controller => "teams", :action => "myteams", :id =>invite.id, :command => "delete"},
          :class => "deleteTeam", :remote => true %>
  </h3></li>
<% end %>
</ul>

<h3 style="text-decoration:underline;">My teams:</h3> <ul style='list-style-type: none; line-height:20pt;' id = 'acceptedList'>
<% current_user.team_users.where(:confirmed => true).order("created_at DESC").each do |invite| %>
  <li class='team' id="<%= dom_id(invite) %>" >
  <h3>
  <% if invite.team.owner == current_user.id%><i><% end %>
  <%=link_to invite.team.name, 
          :controller => "teams", :action => "show", :id => invite.team.id %></i>
  <%=link_to image_tag("delete.png"), 
          {:controller => "teams", :action => "myteams", :id => invite.id, :command => "delete"},
          :class => "deleteTeam", :remote => true %>
  </h3></li>
<% end %>

  </ul>

  <h3><center><%= link_to "Create a Team", new_team_path %></center></h3>
</div>

Once again, it is only the newly created li that does not respond when the “delete” icon is clicked. The existing li’s work fine. Help!

  • 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-31T18:55:22+00:00Added an answer on May 31, 2026 at 6:55 pm

    I don’t speak Ruby but it sounds to me you need to use $.on() because the element doesn’t exist when the DOM is first loaded.

    $('li.team').on('click', '.deleteTeam', function() {
         // and the peasants rejoice!?
    });
    

    If you are on jquery version < 1.7.1 you should use:

    $('.deleteTeam').live('click', function() {
         // and the peasants rejoice!?
    });
    

    credit keviv for acknowledging the little people.

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

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.