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

140
Views
Issues with id bind in Alpinejs

I'm using Laravel and blade components to create reusable components.

I'm trying to bind id dynamically, when component is initialized, but without success.

My blade component code is

<x-general.choices data-id="choicejs-categories" data-receiver="posts" />

<div {{ $attributes }} x-data="$store.choicesData()" @datareceiver.window="setData($event.detail)">
    <select :id="choicesjsId" class="my-js-choice form-control"></select>
</div>

My Alpine code is

document.addEventListener('alpine:init', () => {
   Alpine.store('choicesData', function () {
      return {
         choicesjsId: '',
         init () {
            this.choicesjsId = this.$root.dataset.id;
            console.log(this.choicesjsId);
            console.log(document.getElementById(this.choicesjsId));
         }

The output is:

choicejs-categories
null

Note that when I do console.log(document.getElementById(this.choicesjsId)); null is returned.

What am I doing wrong? Because is null I can't initialize choicesjs plugin.

Any tips?

Regards

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!