Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

112
Vistas
Alpine js get original element in bind method

Assuming I want to get the original element within the Alpine.bind method, how would I do that? So I can retrieve properties like $el.targetName,$el.style, $el.onclick etc For example, if I have :

<script>
    document.addEventListener('alpine:init', () => {
        Alpine.bind('SomeButton', () => ({
            type: 'button',
 
            '@click'() {
                // How would  i get the target element with ll its DOM properties
                //So I can retrive properties like  $el.targetName,$el.style, $el.onclick etc
            },
 

        }))
    })
</script>

I've tried $el, this(which only returns a js proxy) etc

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

In a component definition you have to prefix every object with this. to access the active instance of the component. So the solution is just to use this.$el to access the button HTML element:

<button x-data x-bind="SomeButton">Click here</button>

<script>
document.addEventListener('alpine:init', () => {
  Alpine.bind('SomeButton', () => ({
      type: 'button',

      '@click'() {
          console.log(this.$el.textContent)
      },
  }))
})
</script>

This puts Click here in the console on click.

Note: don't forget to add x-data to the button if it does not have an Alpine.js parent element.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda