我有像这样如何将不同的类添加到div中的不同元素?
<div id="test1">
<a id="hello1"> One</a>
<a id="hello2"> Two</a>
<a id="hello3"> Three</a>
</div>
我使用模板和Backbone.js的一个div。在呈现我的视图之前,我想检查设备是否是iPhone或iPad,因为我已经拥有该功能。如果它是一个ipad我想为每个ANCHOR标签添加单独的类。即Class1为hello1,Class2为hello2等。我只有3个元素。我很新,所以有人可以告诉我如何使用Jquery/Javascript来做到这一点。
如果有任何机会有其他信息,我应该提供请让我知道。随着这个,我有一个View.js和一个Routing.js。我试过使用。
$("#hello1").addClass("Class1");
但是,这并没有奏效。任何帮助,将不胜感激。 感谢
编辑 - 这是查看文件
define([ "jquery", "backbone", "baseview", "template" ], function ($, Backbone, BaseView) {
"use strict";
var gohomeView = BaseView.extend({
initialize: function() {
this.constructor.__super__.initialize();
this.events = _.extend({}, this.globalEvents, this.events);
this.delegateEvents();
},
render: function() {
var context = {
pageName: 'Go Home'
},
partials = {
header: this.globalPartials.header,
tabbar: this.globalPartials.tabbar
};
$(this.el).html(templates["go-home"].render(context, partials));
return this;
}
});
return GoHomeView;
});
你错过了' “':'$(” #hello1 “)addClass(” 1类 “);这可能是为什么没有工作';) – Halcyon
是的'失踪”'一个错字? –
为什么不在样式表中使用媒体查询?不需要额外的类。 – epascarello