s

jquery insert after element edit button Edit

author
Murugan Andezuthu Dharmaratnam | calendar 15 September 2020 | 2901

how do i add an element right after another element using jquery? I have an ordered list below & I want to add 'world' right after hello.

<ol>
	<li>hello</li>
	<li>this</li>
	<li>is</li>
	<li>a</li>
	<li>test</li>
</ol>                  
                    

if you use append it will append the element inside the li tag. the solution is to use jquery insertAfter

$("<li>world</li>").insertAfter($("li")[0])

If you use the above code you will get the below output