Jquery to change href

2019-08-16 16:32发布

问题:

I have successfully used some javascript to change the a href when the browser width goes below 767px. Using the same code on a different site the link for the side pop out does not work above 767px but does redirect to the correct page below 767px. Please can you help me make the changes so that the anchor to open the side pop out works above 767px.

site: http://signfit.multi-web-services.co.uk/

jQuery:

jQuery(document).ready(function() {
    jQuery('.pwebcontact229_toggler').off().click(function (e) {
        e.preventDefault();

        if (jQuery(window).width() < 767) {
            window.location = '/contact-us';
        } else {
            pwebContact229.toggleForm();
        }
    });
});

回答1:

The problem was that the event as being fired too early and changing document ready to window load seems to have fixed my issue.

Don't know if this is the correct way as I am an JavaScript novice; seems to have worked for me though!



标签: jquery joomla