I'm facing a challenge. It's not so much about how to do something, but rather how to do it better.
Additionally, I want to dynamically load content into the page when clicking on navigation links.
My query is what would be the best and proper way to achieve this without cluttering the code.
This is how I've approached it up to now:
<li><a class="navelement" data-url="resources/web/loadit.html" href="#">navbar A</a></li>
And here is the jQuery I have used:
$(document).ready(function(){
$('.navelement').click(function(e){
e.preventDefault;
$('#content').load($(this).data('url'));
});
$('.navelement:eq(0)').click();
});
While I like this method, I find myself having to make an ajax call every time I switch navbars.
Another approach that comes to mind is to use CSS to hide/show div elements. Any suggestions or tips would be greatly appreciated.