Reputation: 297
Hey so I found this jsfiddle http://jsfiddle.net/dEHZZ/1/
$('div#thumbs img').click( function() {
$('#mainimg img').prop('src', $(this).prop('src'));
return false; //stop link from navigating
})
scrolling through some questions here, however its not working when i try to implement it here http://ra-yon.com/beta/Test_sites/HFE/products/IR155R926.php
Any ideas?
Upvotes: 1
Views: 100
Reputation: 11807
Put your code in ready method:
$(document).ready(function(){
$('div#thumbs img').click( function() {
$('#mainimg img').prop('src', $(this).prop('src'));
return false; //stop link from navigating
})
});
You instantiate your code before the dom elements are ready.
Upvotes: 1
Reputation: 206048
Your jQuery code is run BEFORE your DOModel is read and ready to be manipulated
Use a document ready
function
$(function(){ // DOM ready to be manipulated
$('div#thumbs img').click( function( e ) {
e.preventDefault(); //stop link from navigating
$('#mainimg img').prop('src', this.src );
});
});
Additionally, in your code I cannot see no link, so actually you dint need any return false
not event-preventDefault()
(I used)
Upvotes: 1
Reputation: 207891
Wrap your jQuery in a document ready call
$(document).ready(function() {
$('div#thumbs img').click( function() {
$('#mainimg img').prop('src', $(this).prop('src'));
return false; //stop link from navigating
})
});
jsFiddle does this for you automatically which is why it's working there.
Upvotes: 0