Endless Appending - Better Battlelog Forums #111578

Post edited 1 x times, last by
This gives me an endless loop of appending the image over and over.
var source = "'" + "test.png" + "'";
var link = "'http://getbblog.com/en/'";
var secondLevel = "<a href=" + link + "><img src=" + source + "></a>";
var topLevel = "<li>" + secondLevel + "</li>";
var hasBadge = $(".forum-threadview-post-tags").has(topLevel).length;
if(hasBadge == 0){$(".forum-threadview-post-tags").append(topLevel);}

Is there something wrong with that if statement?
Whatever's causing it isn't blatantly jumping out at me, but my brain's not really running js/jquery mode right now (neck deep in some embedded toys I'm playing with at the moment).

My guess would be that has() isn't actually picking up the child element properly... trade it out for .find() perhaps? And, barring that working, toss in a unique class in the elements you inject somewhere and do a find against that, count length, and inject if it's missing.
Post edited 1 x times, last by
I found it earlier today. Thanks though. :P
var hasBadge = $(".forum-threadview-post-tags").children().children("a[href=" + badgeLink + "]").length;