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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:33:43+00:00 2026-06-12T08:33:43+00:00

Is it necessary to select the same DOM element and do something to it

  • 0

Is it necessary to select the same DOM element and do something to it for every Backbone View that is rendered? Only one of this View exists at any one time.

For example, say Bootstrap’s Tabs (tabbable plugin) have to be used on a particular backbone View Product. Is it correct to include the tabbable plugin’s initilization code in the render function?

render: function() {

    this.$el.html( this.template( this.model.toJSON() ) );

    // Activate Twitter Bootstrap Tabs
    $('.tab-bar').tab();
    $('.tab-bar .tab:first').tab('show');
    $('.tab-bar .tab').click(function(e) {
        e.preventDefault();
        $(this).tab('show');    });

    return this;
}

Or is there a way to just call this selector once, and it will fire for all elements with class .tab-bar including those that have yet to exist.

Similarly, if I want a click handler on the first tab

$('.tab:first').click(function(){
    console.log('hey!')'
}

do I place it in that view’s render function? If I do, wont it create many click event listeners if the view is rendered multiple times?

  • 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-12T08:33:44+00:00Added an answer on June 12, 2026 at 8:33 am

    You need to bind event listeners in the initialize method, not in the render. Unless you’re going to re-render the DOM element more than once.

    EDIT

    window.myView = Backbone.View.extend({
    
        events: {
            'click #someElementID': 'do_something',
        },
    
        initialize: function(){
            _.bindAll(this, 'render', 'do_something');
        },
    
        .....
    
        do_something: function(e){
            console.log("A click was made!", e.currentTarget);
        }
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm struggle extracting necessary data from this json stored inside php variable. Not yet
struggle extracting necessary data from this complex json stored inside php variable. Via php
Is it necessary that the assignment operator ( = ) always copies the rvalue
I have a one-to-one relation where I use CascadeType.PERSIST. This has over time build
My day to day work flow is something like this: acquire raw data (~50GB)
I have a system that allows a person to select a form type that
The following two queries yield the exact same result: select country, count(organization) as N
I have a query that returns a result set similar to the one below
Given a ResultMap for an iBatis select query, it seems obligatory that all columns
I like to do something like this: UPDATE articles SET live = 1 WHERE

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.