• Resolved redf150flames

    (@redf150flames)


    I added a JavaScript jquery file to my theme and it is being called in the source of the page however not doing what it’s supposed to. I checked the code on JSFidde and it worked perfectly there.

    Any ideas how to fix it?

Viewing 13 replies - 1 through 13 (of 13 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    You need to be checking the browser’s console log for errors when developing with JavaScript.

    Thread Starter redf150flames

    (@redf150flames)

    The error I have with the file is “Uncaught TypeError: Property ‘$’ of object [object Object] is not a function ” so I looked that up and figured out I need to change

    $(document).ready(function () {
        var cw = $('.block-1').width();
    Uncaught TypeError: Property '$' of object [object Object] is not a function
        $('#block-me').css({
            'height': cw + 'px'
        });
    });

    to

    jQuery(document).ready(function () {
        var cw = jQuery('.block-1').width();
    Uncaught TypeError: Property '$' of object [object Object] is not a function
        $('#block-me').css({
            'height': cw + 'px'
        });
    });

    Thread Starter redf150flames

    (@redf150flames)

    Now I have a new problem. The jQuery is making the height 10400 px which is definitely not the width of block-1.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Can you link the webpage with the issue?

    Thread Starter redf150flames

    (@redf150flames)

    Website caseyvassios(dot)com

    Thread Starter redf150flames

    (@redf150flames)

    Does it have something to do with me using a % width value for block-1 and it not converting to px correctly for block-me height?

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Try removing this jQuery:

    jQuery(document).ready(function ($) {
        var cw = jQuery('.block-1').width();
        $('#block-me').css({
            'height': cw + 'px'
        });
    });

    and see if the issue persists.

    Thread Starter redf150flames

    (@redf150flames)

    That’s the whole thing I was wanting to add to make it black block divs squares in the first place :/

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Would it be easier to instead deactivate all plugins?

    Thread Starter redf150flames

    (@redf150flames)

    I’m not sure I understand what you’re saying.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Can you deactivate all plugins?

    Thread Starter redf150flames

    (@redf150flames)

    If I deactivate my Jetpack plugin it will remove all the CSS I have added for whats on my homepage. I can deactivate contact form 7 and my SEO plugin if you want.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    In a normal situation your jQuery will work, as you’ve found on JSFiddle. There is something affecting that jQuery and if it’s not plugins then you need to explore whether there could be anything from your theme. So it would be best to contact your theme’s vendors as we don’t support that theme.

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘JavaScript File Not Working’ is closed to new replies.