In Backbone model views, it seems $(this.el).parent() doesn’t work. What is the best way to select the parent element from within a view?
I am setting el by using tagName: "li" for the view.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
By default, Backbone assigns an empty
divto your view and you can’t access its parent, until it’s been placed in the DOM through your render function.You can use your approach of
$(this.el).parent()if you are allowing Backbone to assign the default emptydiv. You can use thethis.el.parent()if you are assigningelyourself in the constructor to a jQuery object.