What could be causing the JavaScript on my website to not function properly?

I've encountered an issue with the script on my website. Despite double-checking everything and following a tutorial closely, it still doesn't seem to work. Any suggestions or ideas?

Here are the links to my GitHub repository and a preview of the website: GitHub Repository Website Preview

The code snippet:

<body>
    <div class="navbar">
        <div class="container">

            <a class="logo" href="index.html"><span>d</span>bogdanski</a>

            <img id="mobile-cta" class="mobile-menu" src="images/menu1.svg" alt="menu">

            <nav>
                <img id="mobile-exit" class="mobile-menu-exit" src="images/exit1.svg" alt="exit">
                    <ul class="primary-nav">
                        <li class="current"><a href="#">Work</a></li>
                        <li><a href="#">About</a></li>
                        <li><a href="#">Shop</a></li>
                        <li><a href="#">Social</a></li>
                    </ul>
                    <ul class="secondary-nav">
                        <li class="contact-cta"><a href="#">Contact</a></li>
                    </ul>
                </nav>

            </div>
        </div>
    
        <section class="hero">
            hero
        </section>
        
        <script>
            const mobileBtn = document.getElementById('mobile-cta')
                  nav = document.querySelector('nav')
                  mobileBtnExit = document.getElementById('mobile-exit');

            mobileBtn.addEventListener('click', () => {
                nav.classList.add('menu-btn');
            })

            mobileBtnExit.addEventListener('click', () => {
                nav.classList.remove('menu-btn');
            }) 
        </script>

    </body>

Some SCSS styling:

.navbar {
    background: var(--primary-color);
    padding: 1em;

    .logo {
        text-decoration: none;
        font-weight: bold;
        color: var(--secondary-color);
        font-size: 1.2em;

            span {
                color: white;
            }
    }

    ... (additional styling properties)

}

I've searched for errors, even copied the author's code directly from their repository. The expected behavior is for the mobile menu to display and hide when clicking the hamburger menu icon.

Answer №1

Having trouble getting JavaScript to work on your website? To fix this issue, go to the web browser menu and click on "Edit," then select "Preferences." In the "Preferences" window, navigate to the "Security" tab. Within the "Security" tab under "Web content," make sure to check the box next to "Enable JavaScript." Finally, click on the "Reload the current page" button in your web browser to refresh the page.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Navigate to web pages through hyperlinks in a Textview using a WebView on an

Here is the text that needs to be displayed in a text view. I want the hyperlink to open a webview when clicked, while the rest of the text should not be clickable. String value = "Check out this link: <a href="http://www.google.com">Go to Google< ...

jquery dialog content vanishing upon second opening

My jQuery code is set up to display a dialog when a button is clicked. The issue I'm experiencing is that after closing the dialog and reopening it, the text area within the dialog appears empty with only three buttons visible. However, upon subsequen ...

What is the method to display just the final 3 characters within a paragraph?

Is there a way to display only the last three characters of a string using either a method or a string method? I consistently have a 13-digit number, but I specifically require showing only the final three digits. Appreciate any assistance provided. Than ...

What is the process for retrieving the API configuration for my admin website to incorporate into the Signin Page?

My admin website has a configuration set up that dynamically updates changes made, including the API. However, I want to avoid hardcoding the base URL for flexibility. How can I achieve this? Please see my admin page with the config settings: https://i.st ...

When the value of a react state is used as the true value in a ternary operator in Types

Attempting to implement sorting on a table is resulting in the following error: (property) direction?: "asc" | "desc" No overload matches this call. Overload 1 of 3, '(props: { href: string; } & { active?: boolean; direction? ...

Default item dropped using jQuery UI Droppable, no changes to markup structure

Currently, I am utilizing the .draggable() and .droppable() functions to calculate the price of items that are dropped into a container. The calculation is based on the weight of the items and a predetermined price per gram. Now, I am looking to have one ...

What is the process for determining the overall cost of a column in Angular 9?

I am facing a challenge in calculating the total price, total quantity, and total counted(#) of each column in a table. | Item | Price | Quantity | 1 | Mouse | 500 | 1 | 2 | Wire | 100 | 2 | TI:3 | |TP:600 | TQ:3 | < ...

Wave of the figure in three.js

I have sculpted a humanoid figure and now I am attempting to animate the figure waving with its left hand when the waveButton is clicked. I established a hierarchy where the body element is the parent, with leftArm, rightArm, leftLeg, rightLeg, and head as ...

When I try to hover my mouse over the element for the first time, the style.cursor of 'hand' is not functioning as expected

Just delving into the world of programming, I recently attempted to change the cursor style to hand during the onmouseover event. Oddly enough, upon the initial page load, the border style changed as intended but the cursor style remained unaffected. It wa ...

What is the reason for AngularJS not invoking the said function?

I need to trigger a function when the app starts in order to display a modal. I have attempted to do this by... The function is invoked using the onDeviceReady event. document.addEventListener("deviceready", onDeviceReady, false); function onDeviceR ...

Struggling to retrieve the tagName attribute when clicking in JavaScript

I am trying to extract the tagName of any element within an iframe when it is clicked. Unfortunately, my JavaScript code is not working as expected. As a beginner in JavaScript, I would appreciate some guidance on where I might be going wrong. <div cl ...

What is the best way to retrieve the value of an object in PHP?

There seems to be an issue with retrieving the value of an object. When attempting to get the object value, it appears empty. However, when simply echoing the object, there is content and not null. I'm struggling to understand how to access that value ...

What steps can I take to identify and manage a browser's inability to play a media file?

I am currently utilizing a JavaScript utility to stream mp3 content. Unfortunately, there are instances where I direct users to a file that cannot be played due to external factors. In such cases, Firebug displays an error message indicating that the file ...

What is the most effective way to transfer information from one page to another in a PhoneGap application?

I attempted to transfer data from one HTML page to another using two different methods: function reply_click(clicked_id) { window.location = "newsList.html?Title="+clicked_id; } And I also tried: function reply_click(clicked_id) { window.l ...

Can a Vue component in SFC form be utilized as a mixin?

Consider this scenario, where I have a component created in SFC format: // Parent.vue <template> <div> {{ txt }} </div> </template> <script> export default { name: 'ParentComponent', data() { return ...

Retrieving the content of input elements within a div post removal

I have a situation where I need to dynamically add input text fields inside a div and then delete the div while retaining the values of the input field in a variable. Here's an example code snippet that demonstrates this: $(document).ready(funct ...

splitting the array elements in JavaScript

I'm having trouble with my code that is supposed to separate the array in customer and customerportals. let j = 0; let k = 0; let myVar = []; $.each(Object.customer, function(index, value) { $.each(value.portal.customerPortal, function(innerIn ...

There is a conflict between LightBox and jquery.animate-enhanced that needs to be

I recently added two plugins to my webpage - LightBox and animate-enhanced. While both are functioning correctly, I have encountered an issue. When clicking on images to display LightBox, the modal dialog appears fine; however, the lightboxOverlay is displ ...

Attempting to extract the desired aggregations from a two-dimensional JSON array

Looking to parse through this JSON 2D array (snapshot data example below) to calculate the total cases and deaths for each date, disregarding the state column. While achievable in SQL, it poses a challenge in JavaScript. Ultimately, the summarized data wi ...

After making an Ajax call using AngularJS in a PHP file, I expected to receive only a success or fail message. Instead, I received the entire HTML page code along

After making an Ajax call using AngularJS in a PHP file, I expected to receive only a success/fail message. However, I ended up receiving the full HTML page code along with tags. Here is my AngularJS code: $http.post('ajax_Location.php',{ &apos ...