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

352
Vistas
Why am I having a problem accessing $el in my view in BackboneJS?

I'm trying to utilize the append method through the el in the BackBoneJS view. I'm using Handlebars.

When I run my code, I get this in the console:

main.js:14 Uncaught TypeError: Cannot read properties of undefined (reading 'html')
    at d.render (main.js:14:14)
    at main.js:23:43

Here also are the console logs and responses to the following:

videoViewer.el
  <div>​</div>​

videoViewer.$el
  undefined

Here is my JavaScript:

const VideoViewerModel = Backbone.Model.extend({
  defaults: {
    video: '',
    title: '',
    description: ''
  }
})


const VideoViewerViewer = Backbone.View.extend({
  template: Handlebars.compile($('#video-view-template').html()),

  render: function () {
    this.$el.html(this.template(this.model.attributes))
  },

});

const videoModel = new VideoViewerModel();

const videoViewer = new VideoViewerViewer({ model: videoModel });

$('.viewer-container').append(videoViewer.render().el);

Can anyone catch why my $el seems non-existent?

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

0

It turns out that I had some other problems that were more fundamental. I hadn't installed underscore (I falsely assumed that it was part of the BackBone package).

I also had the dependencies improperly linked in the <head>.

It needed to look like this:

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="style.css" />
    <title>Backbone YouTube</title>
    <script src="node_modules/jquery/dist/jquery.min.js"></script>
    <script src="node_modules/underscore/underscore-min.js"></script>
    <script src="node_modules/backbone/backbone-min.js"></script>
    <script
      type="text/javascript"
      src="./node_modules/handlebars/dist/handlebars.min.js"
    ></script>
  </head>
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