Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

267
Views
How clone and init Datepicker via vanilla JS correctly in Tailwind Elements?

I use Tailwind Elements library with Tailwind CSS in my project. Everything works perfectly, but there is one problem appeared... because I'm trying to clone the element and add to the page a copy.

I do the clone of a form with cloneNode method like this:

  1. I have hidden HTML template:
<template id="temp">
  <form>
    <div class="datepicker relative mb-3" data-mdb-toggle-button="false">
      <input type="text" placeholder="Select a date" data-mdb-toggle="datepicker" />
      <label class="text-gray-700">Select a date</label>
    </div>
  </form>
</template>
  1. When user clicks a button somewhere in the page "+ Add new form", then the new form will be added to the page. There can be many forms as user wants. So I want to use this template to clone it and insert new and new and new nodes to the page. JS:
import 'tw-elements'
let newForm = document.querySelector("#temp").content.cloneNode(true); // clone the <form>
     newForm.appendChild(document.body); // add to the <body>

After these manipulations the new form added to the page, but the Datepicker does not work. As I understood, I should call the initialization of the element programmably via JS like this:

let datePicker = newForm.querySelect('.datepicker');
datePicker.tweDatePicker(); // smth like that maybe

Right? But how? I cannot find in the docs how to call and init the Datepicker (or any other component) via vanilla JS programmably? Maybe you know the better approaches.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!