I am trying to add a twitter script along with some HTML via a for each loop. The loop works fine until I add tags <script>at the end. I am trying to make jQuery spit out my data and then put the twitter button below the information.
I am wondering if there is another way to get jQuery to add a script to my div #entries.
My code is below:
$.each(data.Entries, function(entriesIndex, entriesObject) {
if (entriesObject.Field21 == "Yes") {
if (entriesObject.Field15 == "Yes") {
$("<li />", {
html: '<p><a href="http://twitter.com/share">foo</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></p>'
}).appendTo("#entries");
}
}
});
Update
It seems like it puts the script on the page, but it doesn’t work - it’s not very familiar with how the twitter script works, but I wonder if you guys could help! Thank!
See an example page here: http://bostonwebsitemakeover.com/vote.html
$.each(data.Entries, function(entriesIndex, entriesObject) {
var p, tweet;
if (entriesObject.Field21 == "Yes") {
if (entriesObject.Field15 == "Yes") {
p = $("<p />", {
html: "<p>" + '<a href="' + entriesObject.Field19 + '" target="_blank">' + entriesObject.Field4 + "</p>" + '<img src="http://images.websnapr.com/?url=' + entriesObject.Field19 + '" />' + "</a>"
});
tweet = $('<script>').attr({
type: 'text/javascript',
src: 'http://platform.twitter.com/widgets.js'
});
}
}
$('<li class="entry">').append(p).append(tweet).appendTo('#entries');
});
source
share