Skip Navigation

[Resolved] JavaScript not running

This support ticket is created 5 years, 4 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by stuartm-2 5 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#1347285

I am trying to: run a script that that adds a class to a div with a toggle.

Work fine in a page but dosent work in a view.

function myFunction() {
   var element = document.getElementById("myDIV");
   element.classList.toggle("mystyle");
}

Do i need to add something more?

#1347611

Hello, I see you have a function here that finds an element with the id "myDIV", then toggles the CSS class "mystyle" on that element. Seems okay. Where is the code included - in the View's contents, or in the JS panel of this loop editor? On the standard page where you said this code works, is it triggered with a click event somewhere special, or is it triggered on page load, or focus on a text input, or some other event handler? Share the code you have for that trigger here in your next reply, and share the code you have for the trigger in the View.

You said it doesn't work. Does that mean the CSS class is not being toggled correctly, or the styles from the class aren't working correctly, or what?

It's probably best if I can see this in a browser. Can you provide a URL?

#1347833

The script is inside the view in the JS panel. It just dosent toggle at all. The button is run by the button on top left "Change layout"
This is the page with the view which dosent work:
hidden link

This is a test page i made with html and the js function and it works:
hidden link

Many thanks

#1348231

There is a capitalization difference causing the problem. Your div ID is "myDiv" but the code is looking for "myDIV". Check the JavaScript console to see the error. If you want to fix this you should change the div ID to be myDIV on the page, or change the code to match myDiv</stone>

#1348345

Damn it so easy... thank you Christian as always very helpful.