<ul id="ul"> <li>0</li> <li>1</li> <li>3</li> <li>4</li> </ul> <script> var ul = document.getElementById('ul'); var li = document.createElement('li'); li.innerHTML = '2'; ul.insertBefore(li, ul.getElementsByTagName('li')[2]); </script>