DIV在JS的DIV中包装两个不同的元素

罗恩·杰布(Ron Jb)

想象一下

<div id="container">
     <label>Enter the code</label>
     <input maxlength="5" size="5" class="input_code" title="" type="text" value="" name="code_holder">
     <img src="image.jpg">
     <div class="small-message">Sample Text</div>
     <div class="clear"></div>
     <div id="error-message"></div>
</div>

我只想包装图片和div.small-message带有div类或id的包装

#wrap-inside/.wrap-inside

尝试搜索和试错了一个小时,但没有运气。。我知道这是可能的,有什么主意吗?

阿德内

您可以使用 wrapAll()

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
    jQuery(function() {
        $('img, .small-message', '#container').wrapAll('<div id="wrap-inside" />');
    });
</script>

小提琴

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章