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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:23:53+00:00 2026-06-13T00:23:53+00:00

I am trying to build a function for inserting the number of Facebook Likes

  • 0

I am trying to build a function for inserting the number of Facebook Likes into a Div tag. So far, I have a script that can get the URL from a Div tag which is inside of another Div tag called ‘entry’ and then have the .getJSON() method retrieve the number of Facebook likes for each entry.However, I can’t get each retrieved value of Facebook Likes to insert into a Div tag for each entry. Please note, I simplified my code to where it alerts each Facebook Like value. This is what I have so far:

<div class="entry">
  <div class="fburl">https://graph.facebook.com/zombies</div>
  <div class="facebook-likes"></div>
</div> 
<div class="entry">
  <div class="fburl">https://graph.facebook.com/starwars</div>
  <div class="facebook-likes"></div>
</div>

And here’s my jQuery:

$(document).ready(function(){
$(".entry").each(function() {
    var fbURL = $(this).find(".fburl").html();
    $.getJSON(fbURL, function(fbData) {
        var fbArr = fbData['likes'];
        alert(fbArr);
    });
});
});

​So what I am trying to do is iterate through each entry, get the Open Graph URL for it, retrieve the Likes value, and then insert it into the appropriate Div tag, so the code should render as:

<div class="entry">
 <div class="fburl">https://graph.facebook.com/zombies</div>
 <div class="facebook-likes">2,586 Likes</div>
</div> 
 <div class="entry">
  <div class="fburl">https://graph.facebook.com/starwars</div>
  <div class="facebook-likes">8,905,721 Likes</div>
</div>

​
​

  • 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-13T00:23:54+00:00Added an answer on June 13, 2026 at 12:23 am
    $(document).ready(function() {
        $('.entry').each(function() {
            var $this = $(this),
                fbURL = $this.children('.fburl').html();
            $.getJSON(fbURL, function(fbData) {
                $this.children('.facebook-likes').html(fbData['likes'] + ' Likes')
            });
        });
    });
    

    See: http://api.jquery.com/children

    Demo: http://jsfiddle.net/9EALz/2/

    Note: Using children() is going to be marginally more efficient than using find() as it limits the DOM traversal to a single level ( http://jsperf.com/find-vs-children/13 ). Cashing the jQuery object $(this) via var $this = $(this) is also slightly more efficient as it prevents unnecessary selector interpretation ( http://jsperf.com/jquery-cache-vs-no-chace ).

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

Sidebar

Related Questions

Trying to build a function that can insert into a SQL database regardless of
I'm trying to build a PHP function that allows me to have an array
I'm trying to build a function that will remove all the files that start
I am currently trying to build a program where I have a recursive function
I am trying to build a function that will properly quote/escape an attribute in
I'm trying to build a function that compacts the sprintf function, but somehow I
I am trying to build a php function that would return an array with
I'm trying to build a jQuery function that will allow me to produce a
I'm trying to build a function that takes a PHP image resource and places
I'm trying to build generic function that get from user string and try 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.