如何用 jQuery 包装一些项目?
我有一段无法直接修改的代码:
<div id="registerMessage">
<div class="pageTitle" style="padding:0px 0px 5px 0px;">
Register
</div>
Some bla bla bla
</div>
<input type="hidden" name="ardir" value="" />
<input name="action" type="hidden" value="insert" />
<label>Email </label>
<div>
<input name="user[email]" id="user[email]" type="text" value="" size="35" class="inputReg" />
</div>
<label>Password (5 chars)</label>
<div>
<input name="user[passwd]" type="password" value="" size="35" class="inputReg" />
</div>
<label>Password (confirm)</label>
<div>
<input name="user[password_confirm]" type="password" value="" size="35" class="inputReg" />
</div>
<div id="memomessage">
(Other bla bla bal)
</div>
我需要将第一个标签到最后一个 div
(不包括 memomessage)包装到一个新的 div
中:
<div id="registerBox"> the code of before </div>
I have this code which I can't directly modify:
<div id="registerMessage">
<div class="pageTitle" style="padding:0px 0px 5px 0px;">
Register
</div>
Some bla bla bla
</div>
<input type="hidden" name="ardir" value="" />
<input name="action" type="hidden" value="insert" />
<label>Email </label>
<div>
<input name="user[email]" id="user[email]" type="text" value="" size="35" class="inputReg" />
</div>
<label>Password (5 chars)</label>
<div>
<input name="user[passwd]" type="password" value="" size="35" class="inputReg" />
</div>
<label>Password (confirm)</label>
<div>
<input name="user[password_confirm]" type="password" value="" size="35" class="inputReg" />
</div>
<div id="memomessage">
(Other bla bla bal)
</div>
I need to wrap from the first label to the last div
(memomessage excluded) into a new div
:
<div id="registerBox"> the code of before </div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个 小提琴
Here's a fiddle
使用以下
http://jsfiddle.net/eeusN/1/
use following
http://jsfiddle.net/eeusN/1/
假设您并不特别关心
#memomessage
并且想要获取标签和 div 对,您可以使用 下一个相邻 选择器:工作示例:http://jsfiddle.net/x6pSZ/
Assuming you don't care specifically about
#memomessage
and want to get label and div pairs, you can use the next-adjacent selector:Working example: http://jsfiddle.net/x6pSZ/