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

349
Views
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 answers
Answer question

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 Report
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!