简体   繁体   English

在jQuery中追加div类

[英]append div class within jquery

I have this code: 我有以下代码:

function Filter($container, params, markers) {
  var $label;
  this.markers = markers;
  this.values = {};
  this.key = params.key;
  $label = $('<label />').text(params.label);
  this.$element = $('<select class="form-control input-lg"/>');
  this.$element.append($('<option />').attr('value', 'all').text('All'));
  $container.append($label, this.$element);
}

Essentially, this renders. 本质上,这会渲染。

<label>Category</label>
 <select class="form-control input-lg">
  <option value="all">All</option>
  <option value="Pizza">Pizza</option>
  <option value="Mexican">Mexican</option>
 </select>

But I want it to wrap the above with. 但我想用它来包装上面的内容。

<div class="form-group col-xs-4">
 -- and --
</div>

ANy suggestions please, I have tried almost all variants with no success. 请提出建议,我尝试了几乎所有变体,但均未成功。

Use jQuery Wrap to wrap an element, but in your case I'd go for this: 使用jQuery Wrap包装一个元素,但是在您的情况下,我会这样做:

var formgroup = $("<div class='form-group col-xs-4'/>");
formgroup.append($label, this.$element);
$container.append(formgroup);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM