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
Peaches Stubbs
21,320 PointsI am doing something wrong with including jquery in my site. Please help !
This is how I have included jquery in my site:
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="js/gallery.js" type="text/javascript" charset="utf-8"></script>
This is the code in gallery.js:
$("#imageGallery a").click(function(event){
event.preventDefault();
var href = $(this).attr("href");
console.log(href);
});
This is the html:
<ul id="imageGallery" class="none">
If anybody ses the problem please let me know.
2 Answers
Codin - Codesmite
8,600 PointsIm guessing you might be pointing at the wrong location for your gallery.js file.
Try:
<script src="/js/gallery.js" type="text/javascript" charset="utf-8"></script>
<!-- Or -->
<script src="./js/gallery.js" type="text/javascript" charset="utf-8"></script>
What is the file structure for your root, the html file importing the file and the js folder?
For example:
/root/index.html
/root/js/gallery.js
Peaches Stubbs
21,320 PointsThank you Ashley Skilton, I will try this. I checked it in the console there is something wrong with both paths. The first says failed to load resources, which is the link to jquery. And the other is saying $ is not defined.
Peaches Stubbs
21,320 PointsPeaches Stubbs
21,320 PointsI got ir sorted out. I just needed to correct my url for the first tag. Also the second example that you gave me worked. Thank you so much you rock.