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 trialtobart
13,518 PointsBrowser Preview not working on event.preventDefault();
Hello out there,
probably anyone knows the reason for this behaviour. in the challenge browser everything worked fine as expected to. Rendering in Firefox and Chrome from the workspace isn’t working. Any suggestions in this?
$("#imageGallery a").click(function(event){
event.preventDefault();
var href = $(this).attr("href");
});
Thanks in advance. T!
3 Answers
danagiordano
3,744 PointsI'm not exactly sure what you mean by it's not working. I'm in chrome and that part works fine or rather as expected - but you won't be able to tell until you re-add
console.log(href);
to see it's working via your browser developer tools - because the preventDefault will stop the click from working - but it does grab the link, which is all you wanted ...so it's working but not like "normal" aka, you're not seeing the larger image
Hope that helps
tobart
13,518 PointsHi, thank you very much for your help. Yes, i tried it with different versions of the code.
with
event.preventDefault();
event.stopPropagation();
and also with the console.log(href);
also tested it in my local html editor,
with custom code like this
<ul class"imageGallery">
<li><a class="lin" href="img/Bildmarke.svg"><img src="img/Bildmarke.svg" width="100" alt="Refferal Machine By Matthew Spiel"></a></li>
</ul>
$(".imageGallery").click(function(event){
event.preventDefault();
event.stopPropagation();
var href = $(this).attr("href");
console.log(href);
});
also cleared the cache, tried it with chrome, ff and safari also switched the cdn jquery in the head, not working.
it’s always linking me to the file so i assume that it is some strange behaviour related to my system???
i wll try it further more, but probably it’s somehow an occured issue and someone has a hint.
tobart
13,518 PointsSo i tested once again, it’s only working when i install jQuery locally. When i try it with the linked version of the jQuery Library, it’s not. This is quite wired. Also in addition, as i mentioned, i am able to pass the treehouse test, and my code works fine and gets accepted, but regarding the workspace here on treehouse it is not working, even though i have the right code.