javascript - Unexpected end of input - Stack Overflow

admin2025-04-08  0

I have some issues with a JavaScript portion that I have added to my WordPress footer.php:

<script>
jQuery('.showPosts').on('click', function() {
    if (jQuery(this).hasClass('hidePosts')) {
        jQuery(this).children('div').hide();
        jQuery(this).removeClass('hidePosts');
        jQuery(this).children('.greekCross').html('&#10010;');
    } else {
        jQuery(this).children('div').show();
        jQuery(this).addClass('hidePosts');
        jQuery(this).children('.greekCross').html('&#160;&#10145;');
    }
});
jQuery('.search-field').attr('placeholder','TYPE IN SEARCH TAGS...');
jQuery('.videoText').remove();
jQuery('.ytVideoContainer').addClass('left');
jQuery('.catContainer').addClass('right');
jQuery('.catContainer').addClass('noMarginTop');
var mq = window.matchMedia('(min-width: 767px)');
if (mq.matches) {
    // window width is at least 767px
    jQuery('.relatedVideoThumb').show();
} else {
    jQuery('.postcontentTitle').insertBefore('.catContainer');
    jQuery('.postcontent').insertBefore('.catContainer');
    jQuery('.relatedVideoThumb').hide();
}
var winWidth  = 0;
jQuery(window).resize(function() {
    winWidth = jQuery(window).width();
    if (winWidth < 768) {
        jQuery('.postcontentTitle').insertBefore('.catContainer');
        jQuery('.postcontent').insertBefore('.catContainer');
        jQuery('.relatedVideoThumb').hide();
    } else {
    jQuery('.catContainer').insertBefore('.postcontent');
    jQuery('.catContainer').insertBefore('.postcontentTitle');
    jQuery('.relatedVideoThumb').show();
    }
});
jQuery('.site-header .home-link').css('border', '0');
</script>

Every time I reload the page I receive in the Google Chrome Console the following:

Uncaught SyntaxError: Unexpected end of input

Being minified for optimization purposes I had to look into Firefox Firebug extension to see where exactly is this unexpected end of input. I received the following:

SyntaxError: missing } in pound statement
); }});jQuery('.site-header .home-link').css('border', '0');
------------------------------------------------------------

I don't see where I could had done something wrong, I've more than double check it but I am unable to find the mistake so any guidance or solution is more than weled.

I have some issues with a JavaScript portion that I have added to my WordPress footer.php:

<script>
jQuery('.showPosts').on('click', function() {
    if (jQuery(this).hasClass('hidePosts')) {
        jQuery(this).children('div').hide();
        jQuery(this).removeClass('hidePosts');
        jQuery(this).children('.greekCross').html('&#10010;');
    } else {
        jQuery(this).children('div').show();
        jQuery(this).addClass('hidePosts');
        jQuery(this).children('.greekCross').html('&#160;&#10145;');
    }
});
jQuery('.search-field').attr('placeholder','TYPE IN SEARCH TAGS...');
jQuery('.videoText').remove();
jQuery('.ytVideoContainer').addClass('left');
jQuery('.catContainer').addClass('right');
jQuery('.catContainer').addClass('noMarginTop');
var mq = window.matchMedia('(min-width: 767px)');
if (mq.matches) {
    // window width is at least 767px
    jQuery('.relatedVideoThumb').show();
} else {
    jQuery('.postcontentTitle').insertBefore('.catContainer');
    jQuery('.postcontent').insertBefore('.catContainer');
    jQuery('.relatedVideoThumb').hide();
}
var winWidth  = 0;
jQuery(window).resize(function() {
    winWidth = jQuery(window).width();
    if (winWidth < 768) {
        jQuery('.postcontentTitle').insertBefore('.catContainer');
        jQuery('.postcontent').insertBefore('.catContainer');
        jQuery('.relatedVideoThumb').hide();
    } else {
    jQuery('.catContainer').insertBefore('.postcontent');
    jQuery('.catContainer').insertBefore('.postcontentTitle');
    jQuery('.relatedVideoThumb').show();
    }
});
jQuery('.site-header .home-link').css('border', '0');
</script>

Every time I reload the page I receive in the Google Chrome Console the following:

Uncaught SyntaxError: Unexpected end of input

Being minified for optimization purposes I had to look into Firefox Firebug extension to see where exactly is this unexpected end of input. I received the following:

SyntaxError: missing } in pound statement
); }});jQuery('.site-header .home-link').css('border', '0');
------------------------------------------------------------

I don't see where I could had done something wrong, I've more than double check it but I am unable to find the mistake so any guidance or solution is more than weled.

Share Improve this question edited Oct 6, 2014 at 13:16 ItalyPaleAle 7,3306 gold badges48 silver badges74 bronze badges asked Oct 6, 2014 at 13:09 MariusNVMariusNV 3203 gold badges6 silver badges17 bronze badges 3
  • Your script block is correct, the error is somewhere else. Try to remove this <script> block and check in google chrome again... – dashtinejad Commented Oct 6, 2014 at 13:18
  • Is that the whole javascript code ? Maybe your code starts with $(document).ready(function(){ .. so the }) is missing. – Asenar Commented Oct 6, 2014 at 13:18
  • I figure it out eventually. It's because the minify plugin that I use (WP Super Minify) somehow creates the issue. – MariusNV Commented Oct 6, 2014 at 13:24
Add a ment  | 

1 Answer 1

Reset to default 1

SyntaxError: missing } in pound statement

This error message tells you to add a } is missing at this point.

Try to add it.

I suppose you will also have to add ) to plete your javascript code.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744127945a232550.html

最新回复(0)