Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7176335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:29:10+00:00 2026-05-28T16:29:10+00:00

I’m playing around with Backbone.js for the first time, and I’m having a bit

  • 0

I’m playing around with Backbone.js for the first time, and I’m having a bit of trouble.
My initial intention was to show the content of a certain slide, but I’ve fallen back to ‘just trying to display anything’ with the .text() method.

My render method get’s called, I can see that in the log, but the ‘currentslide’ id is not filled. Does anyone know what silly thing I’m overlooking here?

Seeing as the Backbone code seems to do ok, it might be a jQuery related issue. I’m pretty new to both of them.

Many thanks in advance,

Dieter

This is my html:

<!doctype html>
<head>
<meta charset="utf-8">

<title>Presentation</title>

<script src="js/vendor/jquery-1.5.1.min.js"></script>
<script src="js/vendor/underscore.js"></script>
<script src="js/vendor/backbone.js"></script>
<script src="js/slides.js"></script>
</head>

<body>
  <div id="container">
    <div id="slideshow">
      <h2 id="currentslide"></h2>
</div>
  </div>
</body>

And this is my Backbone code so far:

(function($) {

window.Slide = Backbone.Model.extend({
    content: "Testcontent",
    initialize: function() {
        console.log('Slide created');
    }
});

window.Slidedeck = Backbone.Collection.extend({
    model: Slide,   
});

window.Slideshow = Backbone.View.extend({
    el: $('#slideshow'),
    currentSlide: 0,

    initialize: function() {
        _.bindAll(this, 'render');
    },  
    render: function (){
        console.log('Rendering');

        $('#currentslide').text('This aint even working darned.');
        return this;
    }

});

var slidedeck = new Slidedeck([
    new Slide({
        content: "Slide 1",
    }),
    new Slide({
        content: "Slide 2",
    }),
]);

var slideshow = new Slideshow({
    collection: slidedeck,
});

slideshow.render();

})(jQuery);

EDIT:
I tried the suggestion to replace the last line of code with

$(slideshow.render().el).appendTo('body');

But that doesn’t seem to work unfortunately.

The weird thing is that I have another piece of code with a render() where the .text() works perfectly.

render: function (){
$('#actionValue').text(this.model.get('value'));
return this;
}

Since the render() code gets run on both pieces of code, I assume it has nothing to do with binding anything.
But for some reason the latter does its .text() just fine, the first one does not.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:29:11+00:00Added an answer on May 28, 2026 at 4:29 pm

    In your case, the element #slideshow already exists in your HTML, so you don’t need to append it to the body as specified in @czarchaic’s answer.

    You’re having issues because you’re attempting to render and set the value of #slideshow before it exists in the DOM. This happens because you’ve included js/slides.js before the DOM elements are created. The JS is included and executed, but when slideshow.render() is called, the #slideshow element has not yet been created, so $('#slideshow') will return no elements, thus text() is doing nothing.

    You need to either…

    1. Move your JavaScript include to after the DOM elements creation

      <!doctype html>
      <head>
      <meta charset="utf-8">
      
      <title>Presentation</title>
      
      <script src="js/vendor/jquery-1.5.1.min.js"></script>
      <script src="js/vendor/underscore.js"></script>
      <script src="js/vendor/backbone.js"></script>
      // Remove the include from here
      </head>
      
      <body>
        <div id="container">
          <div id="slideshow">
            <h2 id="currentslide"></h2>
          </div>
        </div>
      </body>
      
      // Put it here
      <script src="js/slides.js"></script>
      
    2. Or you need to wrap your render call in a document ready block

      (function($) {
      
      window.Slide = Backbone.Model.extend({ ... });
      
      window.Slidedeck = Backbone.Collection.extend({ ... });
      
      window.Slideshow = Backbone.View.extend({ ... });
      
      var slidedeck = new Slidedeck([ ... ]);
      
      var slideshow = new Slideshow({ ... });
      
      // Don't render until the elements exist
      $(slideshow.render);
      
      })(jQuery);
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.