jQuery wrapAllInner()吗? -还是将wrapAll()相互应用? [英] Jquery wrapAllInner() ? -- Or wrapAll() applied interally?

查看:55
本文介绍了jQuery wrapAllInner()吗? -还是将wrapAll()相互应用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在<body>之后插入一个开头<div class="container">,在</body>之前插入一个结束</div>

I'm trying to insert an opening <div class="container"> after <body> and a closing </div> before </body>

我希望在元素的html()上有一个像wrapAll()这样的函数可以在内部应用.像wrapAllInner()这样的东西会很棒.

I'd like for there to be a function like wrapAll() that would apply internally, on the html() of an element. Something like wrapAllInner() would be great.

我尝试过:

1) $('body').html().wrapAll('<div class="container"></div>');

这根本不起作用. $("body").html().wrapAll不是函数.奇怪.

which didn't work at all. $("body").html().wrapAll is not a function. weird.

2) $('body').children().wrapAll('<div class="container"></div>');

由于某种原因导致js重复两次.它甚至导致我紧接其后放置的alert()重复两次. ut?

which for some reason caused the js to get repeated twice. It even caused an alert() I placed right after it to get repeated twice. whut?

非常感谢

长时间收听者,首次呼叫者

long time listener, first time caller

推荐答案

只需 .wrapInner() 将单个<body>元素的内容包装在此处的方式如下:

Just a .wrapInner() to wrap the contents of the single <body> element works here, like this:

$('body').wrapInner('<div class="container"></div>');

您可以在此处进行测试.

.html() 不起作用的原因是

The reason .html() doesn't work is .html() without parameters gets the HTML inside the <body> element, a string, which doesn't have any jQuery functions.

这篇关于jQuery wrapAllInner()吗? -还是将wrapAll()相互应用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆