I am stuck in this situation where I have to move a div inside the List. I tried appendChlid and insertBefore but I can't seem to make it work. 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.
Permitted content: Zero or more li , script and template elements.
See: 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.