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

  • Home
  • SEARCH
  • 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 8408077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:32:36+00:00 2026-06-09T23:32:36+00:00

I have a template like this: <a class=btn btn-info btn-small edit model-id=<%= model.id %>

  • 0

I have a template like this:

<a class="btn btn-info btn-small edit"  model-id="<%= model.id %>" href="">
  <i class="icon-pencil icon-white"></i>
  edit
</a>

And a view defined like this:

src.views.WinesView = Backbone.View.extend({
  [...]
  events: {
    'click a.edit': 'edit'
  },

  edit: function(e) {
    e.preventDefault();
    var a = $(e.target);
    var id = a.attr('model-id');
    app.edit(id);
  },
  [...]

if the user clicks on the “edit” text, everything works fine, but if the users clicks on the icon-pencil icon (the content of the tag) the event is correctly raised, but e.target points to the i tag, and not to the a.

In fact, what I want is that if any tag inside the one I binded to tfires an event, I want that event to be raised and to easily get a reference to the element I binded from backbone…

I could solve it with:

edit: function(e) {
  e.preventDefault();
  var a = $(e.target);
  if (a[0].tagName!=='A') { a = a.parent(); }
  var id = a.attr('model-id');
  app.edit(id);
},

but I was wondering if there’s a better, more elegant and generic way to achieve it…

  • 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-09T23:32:37+00:00Added an answer on June 9, 2026 at 11:32 pm

    Look into jQuery’s $.closest() method:

    edit: function(e) {
      e.preventDefault();
      var a = $(e.currentTarget).closest('a');
      var id = a.attr('model-id');
      app.edit(id);
    },
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C++ class like this: class ConnectionBase { public: ConnectionBase(); template <class
I have a templated container class that looks something like this: template <class ItemType>
I have code that looks like this: template<class T> class list { public: class
Suppose I have a function which looks like this: template <class In, class In2>
I have a template base class like this: template<typename T, std::size_t Size> class VectorT
I have a template class that looks something like this: template<class T> class C
I have model like this: class Kaart(models.Model): name = models.CharField(max_length=200, verbose_name=Kaardi peakiri, help_text=Sisesta kaardi
I have a class like this class A_DLL A { ... template <class T>
I have models like this class Blog(models.Model): name = models.CharField(max_length=100) tagline = models.TextField() def
I have a template class which goes like this: class Template{ public $pageTitle =

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.