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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:41:49+00:00 2026-06-12T09:41:49+00:00

I am rather new to backbone, so its possible that i am violating the

  • 0

I am rather new to backbone, so its possible that i am violating the very essence of backbone in doing this. Suggestions are appreciated:

I have made a wall sort of system. So there is a form that can be used to post updates on the wall.

Each update can have comments on them. I am showing 10 updates at a time. So there are 10 comment forms.
So I have a view:

    CommentForm=Backbone.View.extend({
initialize:function(messageView){

},
events:{
    "submit":"postcomment"
},
showMessage:function(data){
      if(data.success)
            type="success";
               else
            type="error";
           message=data.error?data.error:"Update posted successfully";
           $messageContainer=$this.prev();
           console.log($this);
           var html="<div class='alert alert-"+type+"'>"+message+"</div>";
            $($messageContainer).html(html);
},
postcomment:function(){
        $this=$(this.el);

        $.post(baseUrl+"/portal/post-comment",$this.serialize(),this.showMessage,"json");
        return false;
}


   });

Now I create an instance to it as follows:

  commentFormView= new CommentForm({el:$(".comment-form form")});

Note that .comment-form is a div. There are multiple such elements. The event handler gets attached to all the comment forms just fine. But when I use $this=$(this.el); it always refers to the first comment form. How do I solve this. $(this.el) should refer to the current instance of comment form, where the event was triggered and not the first one

  • 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-12T09:41:51+00:00Added an answer on June 12, 2026 at 9:41 am

    One way would be to create a new view for each element using something like this.

    $(".comment-form form").each(function() {
        new CommentForm( { el: $(this) } );
    });
    

    Edit There is another (better?) way. Because the event handler gets the raw event as its first parameter, you can write the handler postcomment like this:

    postcomment:function(evt){
       // ...
    }
    

    Then you can use $(evt.srcElement) to get the actual element.

    postcomment:function(evt){
       $this = $(evt.srcElement);
       // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a rather new C++ programmer. I have made a very simple game
I'm rather new to Backbone.js development, and have run into a bit of a
I'm rather new to Django and I'm using Django 1.0. I have this: forms.py:
I'm rather new to jquery so this may be the issue. I have a
I am rather new to MySQL, I have this problem, which I have searched
I am new to Backbone.js. I have created a View for a button that
Rather new to php, so sorry if this seems stupid. I'm really copying a
I'm rather new to Codeigniter, so I may be going about this the wrong
I'm rather new to MS Build and have been reviewing many of the built
I'm rather new to ClearCase but have searched through a lot of solutions to

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.