Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
erdragerdragsson
Courses Plus Student 5,887 PointsShow twitter news feed on click problem!
Hello, ive been trying to show twitter newsfeed on click on a twitter icon, but i dont know how to put in the embed code to jquery, heres the embed code that i have in a variable
var $twitterfeed = $('<div><a class="twitter-timeline" href="https://twitter.com/username" data-widget-id="4565325235235255">Tweets av @username</a></div>
<script>!function(d,s,id){
var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>');
i have a overlay also, so it gets darker around the body, and it works when i click the image, but when i add this embedded twitter code, everything stops working..
Any ideas?
Kind Regards
Erdrag
1 Answer
Ryan Field
Courses Plus Student 21,242 PointsHi, Erdrag. It looks like you just have some quote issues. You're surrounding your entire value with single quotes, but the code inside that is also using two sets of single quotes, which will break your JavaScript. Try this:
var $twitterfeed = $('<div><a class="twitter-timeline" href="https://twitter.com/username" data-widget-id="4565325235235255">Tweets av @username</a></div>
<script>!function(d,s,id){
var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?"http":"https";if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>');
erdragerdragsson
Courses Plus Student 5,887 Pointserdragerdragsson
Courses Plus Student 5,887 PointsHello, i added the code to the variable, but nothing happend when i do it,
and when i remove this code, then the overlay shows.. So it must be something with the embed code :/
Ryan Field
Courses Plus Student 21,242 PointsRyan Field
Courses Plus Student 21,242 PointsThat's certainly possible. It's hard to tell what that code is actually doing, since it looks minified.
erdragerdragsson
Courses Plus Student 5,887 Pointserdragerdragsson
Courses Plus Student 5,887 PointsThe code is from twitters "widget" thing, where you can get the embed code from your news feed, and i got this code :/
erdragerdragsson
Courses Plus Student 5,887 Pointserdragerdragsson
Courses Plus Student 5,887 PointsAny idea how i could fix this?
heres the full code, so you get the idea