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 trialmichael singh
5,927 PointspreventDefault(); will not work for me....
$('#imageGallery a').click(function(event){
event.preventDefault();
var href = $(this).attr("href");
console.log(href);
});
anyone know what is wrong with my code?
14 Answers
Corin Ashwell
919 PointsOK, go it. Hard refresh of the page, e.g. ctrl + F5, refreshes the HTML so modifications like the id of the ul work.
Marc Mendiola
5,873 PointsThis worked for me.
LaVaughn Haynes
12,397 PointsI updated your code so it displays correctly.
Your code works for me. Do you have a link to jQuery? Not having it is the only reason that I can see at the moment that it wouldn't work.
<!-- jquery included in the line below -->
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<!-- now this script should work -->
<script>
$('#imageGallery a').click(function(event){
event.preventDefault();
var href = $(this).attr("href");
console.log(href);
});
</script>
michael singh
5,927 PointsYeah I have linked it to JQuery, not sure why it will not work on my workspace.
LaVaughn Haynes
12,397 Pointsdo you have an element with the ID of imageGallery? Just checking. If you DO have that and it's still not working can you take a snapshot of your workspace and share the link? If you don't know how let me know and I will tell you.
michael singh
5,927 PointsLaVaughn Haynes
12,397 Pointswhat is it doing on your end? It seems to be working http://screencast.com/t/I8WgiTkcFk
michael singh
5,927 PointsThat is so weird. It still continues to proceed to the link when I click on any of the images....
LaVaughn Haynes
12,397 PointsHmmm, interesting. Did you try refreshing your browser yet? The last time that I saw something weird like this I think it was fixed by refreshing the page
michael singh
5,927 PointsYup, I tried refreshing, even closing out completely.
LaVaughn Haynes
12,397 PointsIf you want to let me know what browser you are using then I could try it in that browser and see if it's something with the browser. That's my only other idea.
michael singh
5,927 PointsI am using google chrome
LaVaughn Haynes
12,397 PointsYep, I use Chrome as well. Windows 10. I'm completely out of ideas on this one (beyond trying clearing your cache or trying to launch workspaces in a different browser). If you don't get it figured out and no one else answers then you might try re-posting the question (they might think this one has been answered and just not marked as answered).
LaVaughn Haynes
12,397 PointsIf you do re-post then include the link to your workspace. That might be helpful. Maybe someone will see what we are looking over
jason chan
31,009 Pointsdocument ready wrap your code in this. If not put the code near end of the </body>
// A $( document ).ready() block.
$( document ).ready(function() {
console.log( "ready!" );
})
alex novickis
34,894 PointsI had some type of similar problem if I had multiple browser windows to the served page closing the window or refresh fixes ...
michael singh
5,927 PointsSo I was able to fix it. I basically had to start over completely in a brand new workspace but now my code works for some reason. Thanks for all the help everyone!
Ryan Southard
2,406 PointsTotally maddening. I've tried everything here: Checked my code, rewritten it and checked it again, reloaded everything, I still go straight to the "dead end," without fail.
My code, unannotated:
$("#imageGallery a").click(function(event){ event.preventDefault(); var href = $(this).attr("href"); console.log(href); });
This seems like a pretty important thing to nail. I'm reluctant to move on until I resolve this. Throw us a bone, Treehouse!
Josh Bennett
15,258 PointsI'm in the same boat.
Corin Ashwell
919 PointsI have this problem. What I notice is that if I view source after previewing the workspace the ul does not have the id imageGallery. I assume this is why the jquery function on the id is not working. I haven't figured out how to correct this yet, any advice gratefully received!
Aaron Selonke
10,323 PointsI also have know idea why mine it is not writting to the consule. Tried the ctrl + F5 and cleared the chrome browser cache.
Here is the screen shot. http://picpaste.com/pics/Captureup-c7ZVbrr8.1456343199.JPG
Derek Gella
15,215 PointsSolution: update the jQuery link in the HTML file to: http://code.jquery.com/jquery-1.11.3.min.js" type="text/javascript" charset="utf-8"> instead of what is pre-loaded in the workspace. The link that is pre-loaded does not work.
jerred poitra
7,241 Pointsjerred poitra
7,241 PointsI have the exact same problem. I've tried every fix here and it won't work. I even started from the beginning twice and still nothing shows up in the console. I don't even think I can progress any further because my workspace will be wrong in the following lessons!