Skip Navigation

[Resolved] jQuery in Toolset View

This support ticket is created 2 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 4 replies, has 3 voices.

Last updated by fahimS-2 2 years, 3 months ago.

Assisted by: Minesh.

Author
Posts
#2544173

Tell us what you are trying to do?
In the Toolset=>Edit View, I can see that there is option to add JavaScript code. Can I use jQuery there?

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#2544297

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi there

Yes, you can use jQuery, but you if you try to use it directly you will likely experience an error because it won't be available yet at the time the View is added to the page and your code is parsed.

You need to use vanilla JavaScript to wait for the document loaded event before setting up jQuery for use, which you can do as in this example:

document.addEventListener("DOMContentLoaded", function () {
    (function ($) {

        //jQuery here
        $('body').css("border", "5px solid purple");

    })(jQuery);
});
#2544403

Hi, thanks for your reply.

Can I use Jquery with 3rd party plugins which let me add custom javascript code?

And can I remove the '$('body').css("border", "5px solid purple");' line from the above code?

#2544863

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Yes, you can. But you should make sure that you should add your custom Javascript/jQuery code with meaningful related events.

Yes, you can remove that line of code that is shared by Nigel.

#2544963

My issue is resolved now. Thank you!