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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:23:19+00:00 2026-06-14T15:23:19+00:00

I am evaluating moving some jQuery code to Backbone and have a total noob

  • 0

I am evaluating moving some jQuery code to Backbone and have a total noob question. I have a large set of jQuery events that exist on just standard html (not associated with a backbone view). What is the proper place to handle those. Something simple in jQuery:

<div class='my-thing'>click me</div>
<script>
  $(document).ready(function(){
     $('.my-thing').on('click',function(){
       alert('say hello');
     });
  });
</script>

In Backbone, it would seem to be something like:

events: {
     "mouseenter .my-thing":"say_again"
 },
 say_again: function(){
   alert('i want to say something');
 },

But where would I put this? Or structure this?

thx in advance

  • 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-14T15:23:20+00:00Added an answer on June 14, 2026 at 3:23 pm

    Typically you would organize them by view — that’s where you declare the events. This requires modularizing the layout of your UI to make it possible to restrict each event to the scope of the view.

    Template

    <script type='text/template' id='say-template'>
        <div class='say-container'>
            <div class='my-thing'>click me</div>
        </div>
    </script>
    

    View

    var SayView = Backbone.View.extend({
        initialize: function() {
            _.bindAll(this, "render");
            this.render();
        },
    
        el: "#container",
    
        template: _.template($("#say-template").html()),
    
        events: {
            "mouseenter .my-thing": "say_again"
        },
    
        say_again: function() {
            alert('i want to say...');
        },
    
        render: function() {
            this.$el.html(this.template());
        }
    });
    
    var sayView = new SayView();
    

    HTML

    <div id="container"></div>
    

    Here’s a working demo.


    Of course, nothing is stopping you from wiring up events in the normal way in the global scope of the application, if you need to. It’s just best to avoid as doing that tends to break the MVC pattern.

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

Sidebar

Related Questions

Evaluating Tinymce. I've looked at the docs/source/api, and have a question that I thought
I am evaluating the Backbone-Relational plugin for modeling a tree. I have the following
While evaluating the advantages and disadvantages of moving our Subversion-based repository over to Git,
When evaluating dojo.require statements, dojo tracks which modules and resources have been required and
When evaluating the value of myObject.myMember My guess is that javascript will try to
Possible Duplicate: Evaluating a string as a mathematical expression in javascript I have written
I am currently evaluating Install4J for my company. We have a use case where
While evaluating ICEfaces I have used Eclipse and its Web Page Editor to visually
While evaluating Visual Studio 2010 Beta 2, I see that in the converted directory,
We are evaluating Shiro for a custom Saas app that we are building. Seems

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.