I am trying to make it so that this code I wrote doesn't rely on having to access the dom in order to use its contents. I had already accessed the dom once before using jquery, and I want to be able to use the jquery I wrote instead of writing new code to access it. Here is my code so far:
constructor($navigation, $content) {
if ($navigation.length == 0 || $content.length == 0) {
return;
}
var nav1 = document.getElementById("main-nav");
var btns = nav1.getElementsByClassName("nav");
for (var i = 0; i < btns.length; i++) {
btns[i].addEventListener("click", function () {
var current = document.getElementsByClassName("active");
current[0].className = current[0].className.replace(" active", "");
this.className += " active";
});
}
$navigation.on('click', 'li', function () {
$content.hide();
$($content[$(this).index()]).show();
});
}
And here is where I had accessed the dom in another document:
new Faq($("#main-nav"), $("div[class='faq-container']"));
what I want to do is make is so that var nav1 and var btns can make use of $navigation and $content, instead of accessing the dom directly. Do I have to somehow convert this code to jquery? how would I approach that?