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?
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?
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
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>
Damn it so easy... thank you Christian as always very helpful.