0

我在 js 创建动态 html 的 magento 环境中工作。现在我想将一个元素移到另一个元素之前。因为这可能是因为 html 也在加载表单 js 并且将应用替换?我的最终 html 代码显示为:

<div class="x-tree-node-el folder active-category x-tree-node-collapsed" id="extdd-3"><span class="x-tree-node-indent"><img class="x-tree-icon" src="http://extjs.com/s.gif"></span><img class="x-tree-ec-icon x-tree-elbow-plus" src="http://extjs.com/s.gif" id="ext-gen27"><img unselectable="on" class="x-tree-node-icon" src="http://extjs.com/s.gif" id="ext-gen24"><a tabindex="1" href="#" hidefocus="on" id="ext-gen21"><span unselectable="on" id="extdd-4">Laptops (2)</span></a><input type="checkbox" class="copycate" value="110" name="tree['110']"></div>

我想在锚标记之前移动输入 typ="checkobx"。就像我的最终结果一样

 <div class="x-tree-node-el folder active-category x-tree-node-collapsed" id="extdd-3"><span class="x-tree-node-indent"><img class="x-tree-icon" src="http://extjs.com/s.gif"></span><img class="x-tree-ec-icon x-tree-elbow-plus" src="http://extjs.com/s.gif" id="ext-gen27"><img unselectable="on" class="x-tree-node-icon" src="http://extjs.com/s.gif" id="ext-gen24">
<input type="checkbox" class="copycate" value="110" name="tree['110']">
<a tabindex="1" href="#" hidefocus="on" id="ext-gen21"><span unselectable="on" id="extdd-4">Laptops (2)</span></a></div>

我尝试此代码但不起作用。

 <script>
  $('.copycate').insert({
  before: "<a>",
  after: "<img>"
});
  </script>
4

1 回答 1

0
$('.copycate').insertBefore($('#ext-gen21'));

jQuery API - 插入之前

于 2013-03-27T07:35:18.573 回答