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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:56:49+00:00 2026-05-31T00:56:49+00:00

I am populating a list of friends using an ajax call to a php

  • 0

I am populating a list of friends using an ajax call to a php script that returns a json array . I am populating each list item with the friends name and putting a button next to it. The name and the button are both in the list item. I want to find the friends name when i click on the button so I can then post it to another script that will remove them from the friends list. As well, I need to select the entire list item when the user clicks on the side button so I can immediately remove it from the unorganized list. The issue that I am having is that I am trying to call something like $(this).find(‘font’).text(); but this is only referring to the button that was clicked and not the entire list item. I’m sure it’s something simple that I’m overlooking but it has been giving me grief for too long now.

The HTML

<ul data-role="listview" data-inset="true" id="friends" data-theme="a" 
data-divider- theme="a">
    <li data-role="list-divider"><h3>Friends</h3></li>
</ul>

The Javascript

    function getFriendsList(){
    var searchType = "friend";
    var friendList = "";
        var friendName = "";
        var friendPoints = "";
    var name = "";
    $.post('friendScript.php', {
        searchType : searchType,
    }, function(data){
        $.each(data, function(index, value){
            $.each(value, function(index, item){
            if(index == 0){
                friendName = item;
            }
            if(index == 1){
                friendGratii = item;
            }   
        });
        friendList += '<li class="friend"><a href=""><h3>' + 
                                  '<font id="friendsName">' + 
                                  friendName + 
                                  '</font>' + " - " + 
                                  friendPoints + 
                                  '</h3></a>' + 
                                  '<a href="" id="defriend" data-icon="delete">' +
                                  "Remove Friend " + '</a>' + '</li>';
    });
    $('#friends').append(friendList).listview('refresh');
            $('#friends').find('li:has(font)').find('#defriend')
            .unbind("click").bind("click",  
                function(){
        var clickedFriend = $(this);
            name = $(this).find('.friend').text(); //HERE IS THE PROBLEM IT 
                                                        //ALWAYS RETURNS AN EMPTY STRING
                        $.post('defriendScript.php', {
                friendName : name,
            }, function(data){
                if(data != "success"){
                alert(data);
                }
                if(data == "success"){
                    $(clickedFriend).remove();
                }
            });
        });
    }, "json"); 
    };
  • 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-31T00:56:51+00:00Added an answer on May 31, 2026 at 12:56 am

    You are doing this:

    name = $(this).find('.friend').text();
    

    $(this) will be the #defriend element, which is a child of your <li>. Doing $(this).find('.friend') will search for elements with class friend within your button. whichi is not what you want. Try this:

    name = $(this).parent().text();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am populating the list view with data I am getting from a JSON
I am populating a list of checkboxes from a foreach loop, and giving each
i have a dropdownlist that populates from the sql server database. populating the list
I have a ComboBox that I am populating with a list of parts for
I'm using jqWidgets with ASP.MVC. I am populating a dropdown list, when the form
As the title indicates I'm populating an Infopath textbox control using a SharePoint list
I am populating a list of names that will be added to my Sql
I am populating a list using List<Country> countries = new List<Country> { new Country()
Using C#, I am noticing a significant difference in perfomance when populating a list
I have an activity that has two tabs and a list view in each.

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.