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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:02:59+00:00 2026-06-18T00:02:59+00:00

I have a backbone application that gives the user the option to display a

  • 0

I have a backbone application that gives the user the option to display a map by clicking a button. In the CharactersView, the ‘showMap’ event is set up (triggered by clicking the #map_button) with the corresponding showMap function to display a map once the event’s triggered. The CharactersView also renders the character_template, and the character_template contains the #map_button and the actual map code with the class ‘map.’Everything works fine if the #map_button is located in the same template (the chracters_template) as the map, which gets rendered from CharactersView. However, if I move the #map_button outside of the character_template (for example, into another template or directly into the body of the page), then the showMap event in CharactersView is no longer triggered, and the map no longer gets displayed in the character_template. Note, I am waiting until the characters template gets rendered to the page before I try to click the #map_button and it’s still not working.

From the above description and the code below, can you tell me what the issue here might be and how I might solve it.

Code

Set up event binding in CharactersView so that a map is displayed when a button is clicked

 events: {

  'click #map_button' : 'showMap'

},

showMap: function(){

      $(".map").toggle();
    }

The character_template rendered by the characters view. The actual map with the class ‘map’ that gets displayed is in the same template that gets rendered by the characters view.

<script id="character_template" type="text/x-handlebars">
    <input class='action_button' id='map_button' type='button' value='Show Map' />

   <%= image_tag "http://maps.google.com/maps/api/staticmap?size=300x200&sensor=false&zoom=12&markers={{ latitude }}%2C{{ longitude }}", :class => "map" %>
    </script>

If I removed the button from the character_template and put it in another tempalte, the click #map_button event in CharactersView no longer works. It’s also the same result if I just put the button directly in the body of the html.

… other code ommitted…

  • 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-18T00:03:02+00:00Added an answer on June 18, 2026 at 12:03 am

    When you set events in a view using the events hash, Backbone eventually uses jQuery to listen to the event. In Backbone.delegateEvents, you can see this code:

    this.$el.on(eventName, selector, method);
    

    Using this.$el.on() (where ‘this’ is your view) is only listening for the event within that view’s DOM element ($el is a cached jQuery object).

    So, if you move the button to another view, you need to add your event listener to that view as well:

    events: {
    
      'click #map_button' : 'showMap'
    
    },
    

    Basically, using the views event hash is saying, ‘listen to this event only within this view’s DOM element.’

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a User model in a Backbone application that makes an ajax request.
I have a Backbone.js application that allows users to create graphs based on large
In my Backbone application I have a main view that shows previews of posts.
We have a backbone.js app that displays a number of forms to the user.
I have an application that allows the user to drill down through data from
I have a backbone application that has a number of views. Switching between views
I have an application that I want to create using Backbone Marionette. Basically, it's
I have a web application that is currently using backbone.js 0.5.3 with backbone local
In my backbone.Marionette application I have a Model that requires an Id attribute to
I have a Backbone application that appends elements to the DOM. When I log

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.