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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:45:04+00:00 2026-05-25T17:45:04+00:00

So I am creating a TagCloud for my site and am having issues being

  • 0

So I am creating a TagCloud for my site and am having issues being able to use JQuery to alert me of the selected link.
The site created the links just fine, gives them the class of ‘tagLink’, but when I try to alert the number of elements with that class, it gives me 0.
Any ideas??
Here is my code:

    $(function() {  
    //get tag feed  
    $.getJSON("tagcloud/tagcloud.php?callback=?", function(data) {  
          //create list for tag links  
        $("<ul>").attr("id", "tagList").appendTo("#tagCloud");  
        //create tags  
        $.each(data.tags, function(i, val) { 
            //create item  
            var li = $("<li>");  
            //create link  
            $("<a>").addClass('tagLink').text(val.tag).attr({title:"See all pages tagged with " + val.tag, href:"tags/" + val.tag + ".php", id: val.tag}).appendTo(li);  
            //set tag size  
            li.children().css("fontSize", (val.freq / 10 < 1) ? val.freq / 10 + 1 + "em": (val.freq / 10 > 2) ? "2em" : val.freq / 10 + "em");
            //add to list  
            li.appendTo("#tagList");  
        });   
    }); 

     //Increase database if link is clicked 
    alert($('.tagLink').size());//Test how many exist
    $('.tagLink').click(function(){
        var id = $(this).attr('id');
        $.ajax({    
            url: "tagcloud/tagcloud.php",
            type: "POST",
            data: {clicked : id}
        });
    });


});
  • 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-25T17:45:05+00:00Added an answer on May 25, 2026 at 5:45 pm

    getJSON is asynchronous so your selector gets run before the tag links get added. Move the taglink click handler assignment inside your AJAX callback.

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

Sidebar

Related Questions

Creating a site in with FrogCMS and using alot of jquery to create an
this module does a good job at creating a tagcloud block - all good
Creating a server-side socket will fail if I'm trying to use the same port
Creating Trial .git -repo $ mkdir Test; cd Test; git init $ echo Just
creating a filter for a select menu and having a few problems! the first
I'm having a Repeater used as a sort of Paging TagCloud. To do so,
Creating a link in PHP: echo <a href=\$currentFile?rowID=$row['id']\>click here</a>; This throws an error: Parse
My project contains tagcloud and I am following the sample on: http://www.mikesdotnetting.com/Article/107/Creating-a-Tag-Cloud-using-ASP.NET-MVC-and-the-Entity-Framework My problem
I'm creating a simple tag system that allows me to link a tag to
Creating a link to an issue in Mantis is done via the hash symbol

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.