-
Your examples show creating the toggle from a previous created input.
I need to dynamically create elements and turn them into toggles. Any suggestions because the code below give the error:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi, You should add the input to DOM and then transform it to a toggle. The plugin do not replace the reference of the input, the input is preserved wrapped into the toggle. Here a live demo https://codepen.io/palcarazm/pen/ExGKqaB // Create input
const toggle = document.createElement("input");
toggle.type = "checkbox";
// Add input to DOMM
const parentNode = document.querySelector("section");
parentNode.appendChild(toggle);
// Transform to toogle
toggle.bootstrapToggle(); |
Beta Was this translation helpful? Give feedback.
-
Thank you very much. I have been using the plugin for a while. This is the first time creating it dynamically. I really like the look and feel. The toggle allows the user to see just the Open or Closed assay selections instead of a long, long list. Most of the time they are only concerned with the Open assays (smaller list). BootstrapToggle.implementation.mov |
Beta Was this translation helpful? Give feedback.
Hi,
You should add the input to DOM and then transform it to a toggle.
The plugin do not replace the reference of the input, the input is preserved wrapped into the toggle.
Here a live demo https://codepen.io/palcarazm/pen/ExGKqaB