more flexible tagName in Backbone.js view

backbone.js, html, jquery

Solution

You can provide any arbitrary attributes that you want for the view's tag using the 'attributes' attribute:

Backbone.View.extend({
  tagName: "select",
  attributes: {
    "multiple": "multiple"
  }
});

Problem

I am trying to force the 'multiple'='multiple' attribute on a select option tag view which is a Backbone view using jQuery selector with the attr function but I can't seem to make it work. Here's my code: ``` window.MyListView = Backbone.View.extend({ tagName:'select', className: 'mySelect', initialize:function () { }, render:function (eventName) { $(".mySelect").attr('multiple', 'multiple'); _.each(this.model.models, function (myModel) { $(this.el).append(new MyListItemView({model:myModel}).render().el); }, this); return this; } ``` Not working at all. Any ideas or any other ways around this? Would I be better off creating a new view with only a select multiple tag and then append the myListItemView object to it? Thanks a bunch, Jimmy

Original source