function addSelected(clicked_id){
const ul = document.getElementById('sortable2');
const listItems = ul.getElementsByTagName('li');
if(clicked_id == "add1")
{
const pickNewUl = document.getElementById("slottable1");
}
else if(clicked_id == "add2")
{
const pickNewUl = document.getElementById("slottable2");
}
// Loop through the NodeList object.
for (let i = 0; i <= listItems.length - 1; i++) {
if(listItems[i].className=="selectedli")
{
console.log (listItems[i]);
var createLi = document.createElement("li");
createLi.id = listItems[i].id;
createLi.innerHTML = listItems[i].textContent;
pickNewUl.appendChild(createLi);
listItems[i].classList.remove('selectedli');
}
}
}
Please check above code.
I am trying to copy selected li to a new ul list which is sucesfully done by the code above.
Issue is, I am not getting the value of “pickNewUl” in for loop outside of if else.