Wordpress: my JS files don't execute any of their code and they don't return 404 error
Here's my jQuery code:
jQuery(document).ready(function() {
var $window = jQuery(window);
console.log("Pre-page height: " + $window.height());
jQuery('.main-content .home-block').height($window.height());
$window.on('resize', function(){
console.log("Resize event height: " + $window.height());
jQuery('.main-content .home-block').height($window.height());
});
});
This is my current code <head>
:
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<title><?php cs_wp_title(); ?></title>
<?php if( ! cs_get_option( 'non_responsive' ) ) { ?>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<?php } else { ?>
<meta name="viewport" content="width=1200">
<?php } ?>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.4.js" />
<!-- Start of imported scripts -->
<script type="text/javascript" src="/js/customjs/main.js" />
<script type="text/javascript" src="/js/panelsnap/jquery.panelsnap.js" />
<!-- End of imported scripts -->
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
<?php if ( is_search() || is_404() ) { echo '<meta name="robots" content="noindex, nofollow" />'; } ?>
<?php if ( cs_get_option( 'favicon' ) ) { echo '<link rel="shortcut icon" href="'. cs_get_option( 'favicon' ) .'" />'; } ?>
<?php wp_head(); ?>
</head>
My console is clean and there is no visible error. Nothing strange happens on my page. What is the problem?
+3
source to share
1 answer
Ok, here's a lesson learned well:
Always check your CDN for jQuery.
He did not work. Normal console.log
or alert
gave me an answer, but nothing with jQuery selector will work.
I switched from CDN jQuery:
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.4.js" />
On Google CDN
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
And he started to work.
+2
source to share