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

171
Vistas
Make content editable div get focus on button click

I have a content editable div that I'm using to retrieve some data.

<div contenteditable="true" ref="test">/*SomeText*/</div>

After running the focus through the ref with this.$refs.test.focus(). It didn't work and I get an error on the console (Cannot read properties of undefined reading focus) How can I trigger a focus effect on content editable div?

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

0

The attribute for content editable should not be content-editable="true", but instead contenteditable="true".

const App = {
  el: '#app',
  methods: {
    focusDiv() {
      this.$refs.test.focus()
    }
  }
}

const app = new Vue(App)
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

<div id="app">
  <div contenteditable="true" ref="test">My Div</div>
  <button @click="focusDiv">Focus on div</button>
</div>

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