I am simply trying to append an a-tag into a li, but for some reason I cannot see why this doesn't work.
navListItem = '<li class="p-list-item"></li>';
mainLink = '<a class="main-a" href="' + item.link + '"><span>"' + item.title + '"</span></a>';
$(navListItem).append(mainLink);
Your navListItem does not exist yet.
append it to another html element first and change the last line to:
$(".p-list-item").append(mainLink);
Seems legit and work for me.
Did you append the navListItem to a real html-element in the DOM?
$(document.body).append(navListItem);
You need something to append it to
var item = {
link:"javascript:void(0)",
title: "title"
};
navListItem = '<li class="p-list-item"></li>';
mainLink = '<a class="main-a" href="' + item.link + '"><span>"' + item.title + '"</span></a>';
var z = $(navListItem).append(mainLink);
$("#container").append(z);
here is a jsfiddle http://jsfiddle.net/6vy5efeu/