Skip to content

How to use the JS variable in the content? #372

Closed Answered by jekuer
szewingleung asked this question in Q&A
Discussion options

You must be logged in to vote

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...

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 m…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jekuer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants