How to use the JS variable in the content? #372
-
originally, the code is like this: but if i want to use the js variable inside the parameters, and to use the js variable as the content inside the calendar, what should i do? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @szewingleung, I am not exactly sure what you are after. const addBtn = document.querySelector('add-to-calendar-button');
const currentDate = new Date();
const formattedDate = currentDate.toISOString().slice(0,10);
addBtn.setAttribute('startDate', formattedDate); This selects the button (assumes there is only 1 - otherwise, set a unique ID), gets the current date, formats it, and updates the respective attribute. With a JavaScript framework (like React or Vue) in place, it would be even easier. Check out the Guides at https://add-to-calendar-button.com/#installation for more details on that. |
Beta Was this translation helpful? Give feedback.
Hi @szewingleung,
I am not exactly sure what you are after.
The code behaves like a regular HTML element.
So, if you want to change a parameter, you could do something like...
This selects the button (assumes there is only 1 - otherwise, set a unique ID), gets the current date, formats it, and updates the respective attribute.
With a JavaScript framework (like React or Vue) in place, it would be even easier. Check out the Guides at https://add-to-calendar-button.com/#installation for m…