I still poor on javascript especially on JQuery. How to load some content if one of JSTree href is clicked, and the content should loaded on the same page.
When I remove the div id "tree_1" from the div, it work perfect as a navigation menu normally (not as JSTree node).
Please help.
Thank you.
$('#tree_1').jstree({
"core" : {
"themes" : {
"responsive": false
}
},
"check_callback" : true,
"types" : {
"default" : {
"icon" : "fa fa-folder icon-state-warning icon-lg"
},
"file" : {
"icon" : "fa fa-file icon-state-warning icon-lg"
}
},
"plugins": ["state"]
});
$('#tree_1').on('select_node.jstree', function(e,data) {
var link = $('#' + data.selected).find('a');
if (link.attr("href") != "#" && link.attr("href") != "javascript:;" && link.attr("href") != "") {
if (link.attr("target") == "_blank") {
link.attr("href").target = "_blank";
}
//document.location.href = link.attr("href");
return false;
}
});
<div id="tree_1" class="tree-demo scroller" style="height:150px">
<ul id="klass">
<li><a href="home">Load Home Page</a></li>
<li><a href="klassing">Load Klassing Page</a></li>
</ul>
</div>
<div id="content"></div>
<script>
$(document).ready(function(){
$('#content').load('content/index.php');
$('ul#klass li a').click(function(){
var page = $(this).attr('href');
$('#content').load('content/' + page + '.php');
return false;
});
});
</script>
Aucun commentaire:
Enregistrer un commentaire