[英]How to move a div inside <ul> on top of <li>
I am stuck in this situation where I have to move a div inside the List.我陷入了这种情况,我必须在列表中移动一个 div。 I tried appendChlid and insertBefore but I can't seem to make it work.
我试过 appendChlid 和 insertBefore 但我似乎无法让它工作。 The code is as following:
代码如下:
<div class='error'>Content</div> <div class='form'> <ul> <li>Item1</li> <li>item2</li> <li>Item3</li> </ul> </div>
I want the result to look like:我希望结果看起来像:
<div class='form'> <ul> <div class='error'>Content</div> <li>Item1</li> <li>item2</li> <li>Item3</li> </ul> </div>
What is the best way to make this work?完成这项工作的最佳方法是什么?
That is not possible because ul does not allow div elements.这是不可能的,因为ul不允许div元素。
Permitted content: Zero or more li , script and template elements.
允许的内容:零个或多个li 、脚本和模板元素。
See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ul请参阅: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ul
<div class='error'>Content</div>
<div class='form'>
<ul>
<li id="first-li">Item1</li>
<li>item2</li>
<li>Item3</li>
</ul>
</div>
$('.error').insertBefore('#first-li');
Hope this help.希望这有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.