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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:37:58+00:00 2026-06-15T22:37:58+00:00

In a Backbone.js template, templates/nutrients/show_template.jst.ejs, I have this: <div id=nutrient_container> <table class=person_nutrients> … <%

  • 0

In a Backbone.js template, templates/nutrients/show_template.jst.ejs, I have this:

<div id="nutrient_container">
<table class="person_nutrients">
...
<% for(var i=0; i < person[nutrientsToRender]().length; i++) { %>
  <% var nutrient = y[x[i]]; %>
  <tr class="deficent_nutrients">
    <td>
    <span class="nutrient_name"><%= I18n.t(nutrient.name) %></span>
    </td>
    <td><a id="show_synonyms" href="#"><%= I18n.t("Synonyms") %></a></td>
<% } %>
</table>
</div>

Then, in the Backbone.js view, views/nutrients/show_view.js, I have this:

el: 'table.person_nutrients',
parent_el: 'div#nutrient-graphs',
template: JST["backbone/templates/nutrients/show_template"],
initialize: function(options) {
  ...
  this.render()
},
events: {
    'click a#show_synonyms':'synonyms_event'
},
render: function() {
  ...
  $(this.parent_el).append(this.template({person: this.model_object, nutrientsToRender: this.nutrientsToRender(), x: x_prep, y: y_prep}))
}, 
synonyms_event: function(event) {
  alert("I got called");
}

Why doesn’t the event (the alert box) get triggered? I click the link for “Synonyms” and all I get is the root url with a # after it. Why doesn’t the Javascript match up?

  • 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-15T22:37:59+00:00Added an answer on June 15, 2026 at 10:37 pm

    I think you are misunderstanding the way a view’s el works.

    In backbone.js views always reference a DOM element which is its el, this DOM element can either be an existing element in the page’s DOM or it can be a new element that does not exist on the DOM.

    The way views in backbone.js listen to events is by delegating (binding) them to its el. If a view’s el changes, or you want to change what events it listens to you can also manually (re)delegate the events by calling the delegateEvents method

    There are two common patterns with views, one is where a view references an existing element on the DOM (this is done by specifying it’s el property or passing in an el when it’s instantiated), and the second is where the view’s el doesn’t reference an existing element on the DOM and instead renders some HTML in it’s el which is then inserted into the DOM.

    Very often what’s done is that you have one parent view (often a collections view) which references an existing element on the DOM, and then a bunch of child view’s whose el gets appended.

    In your case you probably want to split up your view into a parent view that references a higher container div, and have the child views’ els appended into it.

    For example

    <div id="dvContainer">
    
    <div id="synomCont"></div>
    <input type="button" id="btnAdd" value="add" />
    </div>
    
    
    var ParentView = Backbone.Views.extend({
    
       el: 'dvContainer',
    
       events: {
           "click #add" : "addSyn"
       },
    
       addSyn: function() {
          //here you can create a model with the approptate data, and pass that in to
          // the view
          var view = new SynomView();
          this.$el.find('#synomCont').append(view.render().el);
       }
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the view: class FoursquareSearch.Views.SearchNew extends Backbone.View tagName: 'sidebar' template: JST[templates/search/new_search] #events: #
My class is defined as below: class NewUser extends Backbone.View template : JST[backbone/templates/events/new] events
I have a rails-backbone project that generates jst.ejs templates. I'd like to include some
Specific question: this code works in a backbone template index.jst.eco, but it doesn't work
I have the following template in Backbone, all gets rendered perfectly. <a href=#list data-role=button
I have JavaScript application, where I use client-side templates (underscore.js, Backbone.js). Data for initial
A common pattern for loading backbone templates is something like: <script type='text/template' id='foo'> my
I have a select box that gets populated through a Backbone Collection: class Prog.Views.History
This question is about templating and localizing, using require.js and underscore templates through backbone.js.
Currently in a Backbone project I am working on, I have combined all templates

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.