The navigation (styled with Bootstrap 4) is simply li elements and the ul container waiting for AJAX is
<ul class="nav nav-pills lead" id="navitems"></ul>
Creating an initial nav list with two static (non JSON) items with jQuery .html:
$("#navitems").html('
<li class="nav-item"><a class="nav-link pcl" href="#" id="load_page1">Nav Link 1</a></li>
<li class="nav-item"><a class="nav-link pcl" href="#" id="load_page2">Nav Link 2</a></li>
');
Adding further items with JSON / AJAX
$.getJSON(cfcJSON+'&asite='+asite+'&apost='+apost+'&asort='+asort,
function(data) {
$.each(data.DATA.NAVITEMS, function(i,navitems){
$('#navitems').append(navitems);
return false; // all li items in one string
});
});
Codepen http://codepen.io/xsmobi/pen/MbpxbE (important: not using https)
To be sure that is has not to do with Codepen, I hosted the page here, too https://www.bitballoon.com/sites/testing-ajax-navigation
In both cases
- Building the navigation with jQuery works
- Only those two test links created with ().html() are able to fire
- Those created with AJAX aren't
- Checking elements in developer tools: links look the same (see screenshot in the code)
This is the on.click function, it works for the non-getJSON links
pdx = 0;
$('.pcl').click(function() {
console.log("clicked in doc ready slogan");
pdxx = pdx;
pdx = this.id;
$(".pcl").removeClass('active');
$("#"+pdx).addClass('active');
pdx = pdx.replace("load_", "");
console.log("Nav li clicked with anchor text ...: " + pdx + "!")
});
Tried Need assistance with jquery and ajax and wrapped the on.click in a doc ready (nested in the main document ready) but that does not help