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 8141921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:40:08+00:00 2026-06-06T12:40:08+00:00

I just started with backbone.js, and one thing that I noticed is that sometimes

  • 0

I just started with backbone.js, and one thing that I noticed is that sometimes I do not want any tagName to contain/encapsulate my view’s template code. If I leave it at '' or 'span', I get unneccessary div and span in my code.

The alternative that I found is to remove the containing tag from my template (<div class="photo_box"> in my example as shown below), and use that as the tagName in my view. Most of the time, this tag will contain a class (.photo_box), and I still have to perform an addClass to (this.el). I dont really like scattering up my template code.

Is there another way?

JS

// Views
PhotoListView = Backbone.View.extend({
    tagName: 'span',

    render: function() {
        _.each(this.model.models, function(photo) {
            $(this.el).append(new PhotoListItemView({ model: photo }).render().el);
        }, this);
        return this;
    }
});

PhotoListItemView = Backbone.View.extend({
    tagName: 'span',

    template: _.template($('#tpl-PhotoListItemView').html()),

    render: function() {
        $(this.el).html(this.template( this.model.toJSON() ));
        return this;
    }


});

HTML

<!-- Templates -->
<script type="text/template" id="tpl-PhotoListItemView">
                <div class="photo_box">
                    <div class="photo_container">
                        <img src="img/profiling/<%= photo_id %>.jpg" class='photo' />
                    </div>
                </div>
</script>

Result

<div id="photo_list">
    <span>
        <span>
                    <div class="photo_box">
                        <div class="photo_container">
                            <img src="img/profiling/f_001.jpg" class="photo">
                        </div>
                    </div>
        </span>
        <span>
                    <div class="photo_box">
                        <div class="photo_container">
                            <img src="img/profiling/f_002.jpg" class="photo">
                        </div>
                    </div>
        </span>
    </span>
</div>
  • 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-06-06T12:40:09+00:00Added an answer on June 6, 2026 at 12:40 pm

    You don’t need to manually add the class-name. You can use the className property:

    PhotoListItemView = Backbone.View.extend({
        tagName: 'span',
        className: 'photo_box',
    

    Btw, I recommend this HTML structure:

    <ul id="photo_list">
        <li>
            <img src="img/profiling/f_001.jpg" class="photo">
        </li>
        <li>
            <img src="img/profiling/f_003.jpg" class="photo">
        </li>
    </ul>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just getting started with backbone.js, and one of the things I've noticed is that
Just getting started with Backbone. I have a generic view that can render a
Just started using Java (for Android, if that matters) and all I want is
I just started to delve into backbone.js and I am not sure what is
I've just started using Backbone.js. I want to create a Collection and add some
just started using log4j in one of my home-projects and I was just about
I just started using Matlab, and I absolutely despise (or not properly understand), the
We've just started using Backbone and I'm trying to get a handle on a
I just started learning Backbone.js, and have been working on (what else) a simple
Just started converting our maps from V2 of the API to v3. Got one

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.