Skip to content

Commit

Permalink
Update script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
codingkatty authored Oct 10, 2024
1 parent 3404d60 commit 1362671
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,23 @@ async function runCode() {
}

document.addEventListener('DOMContentLoaded', function() {
// Show the editor when the page loads without requiring user input
showEditor();
// Show the editor only on the page where it is needed
const editorPage = "learn-page"; // Change this to the correct page where the editor should show
if (document.body.id === editorPage) {
showEditor(); // Show the editor only on the specific page
}

// Highlight the active navbar item based on the current page URL
const currentPage = window.location.pathname.split("/").pop(); // Get the current page filename

const currentPage = document.body.id;
document.querySelector(`.navbar a[href="${currentPage}.html"]`).classList.add('active');
// Loop through all the navbar links
const navLinks = document.querySelectorAll('.navbar a');
navLinks.forEach(link => {
// Check if the href of the link matches the current page
if (link.getAttribute('href') === currentPage) {
link.classList.add('active');
} else {
link.classList.remove('active'); // Remove active class from non-matching links
}
});
});

0 comments on commit 1362671

Please sign in to comment.