B.createDocumentFragment is not a function (jQuery)

I play with the function and get

b.createDocumentFragment is not a function (jQuery) 

My function

 function tweetCount(url) { $.getJSON("http://urls.api.twitter.com/1/urls/count.json?url="+url+"&callback=?", function(data) { count = data.count $(this).append(count); }) } 

I tried many different ways, but I can’t understand why he doesn’t like to add. "count" is a number, and something like alert (count) works, but doesn't add!

Any help ?! Alex

+4
source share
1 answer

I do not think this means what you think. Change $(this) to an explicit link to the desired DOM element.

Alternatively, you can define this by calling:

 tweetCount.call($("#element"), url) 

Edit

Try the following:

 $("span.tweetcount").each(function(){ url = $(this).attr('title'); tweetCount.call(this, url); }); 

Or, to save space:

 $("span.tweetcount").each(function(){ tweetCount.call(this, $(this).attr('title')); }); 

Edit 2:

Try replacing tweetCount as follows:

 function tweetCount(url) { var that = this; $.getJSON("http://urls.api.twitter.com/1/urls/count.json?url="+url+"&callback=?", function(data) { count = data.count; $(that).append(count); }) 
+4
source

All Articles