I can’t seem to get this working, even though I have the idea it is perfectly correct. Consider the following code:
<script type="text/javascript>
ul = $(".qtrans_language_chooser");
parent = ul.parent();
activeLangLi = ul.children("li.active");
parent.prepend('<ul class="qtrans_active_language"></ul>');
activeLangUl = $(".qtrans_active_language");
o = activeLangLi.appendTo(activeLangUl);
activeLangLi.remove();
</script>
All I’m trying to do is add activeLangLi to the empty activeLangUl. But no matter if I use append(), appendTo() or add() it never shows up.
Remove this line:
This removes the elements from the DOM.
appendandappendTowill move (not copy) the elements from the current location to the new one. If youremovethem afterwards, well, then they are gone.You could also optimize your code to:
Don’t forget to use
var.