I want to implement this code in the fiddle on my Wordpress site (Agera template). But the code returns the error:
TypeError: Property '$' of object [object Object] is not a function
So that I changed my code to this (switch $ to jQuery):
jQuery('a[href^="#"]').click(function(){
jQuery('body').animate({
scrollTop: jQuery(jQuery(this).attr('href')).offset().top - 30
}, 500);
});
Does not work.
I tried also that (and also changed $ to jQuery, tried both):
jQuery(document).ready(function() {
$('a[href^="#"]').click(function(){
$('body').animate({
scrollTop: $($(this).attr('href')).offset().top - 30
}, 4000);
});
});
Does not work. If I try the code for the successful implementation of jQuery it works ok, as every other jQuery on the page.
What could be the problem? The html markup is correct. Thanks.