• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

263
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 3 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 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error