The element I'm working with is always visible, even before the user interacts with it to activate the onClick function

My drop-down navigation function in Javascript is now working on mobile, which is fantastic. However, I am facing an issue where the drop-down wording on my "About Page" and "Index Page" is constantly showing, even though it should only display after the user clicks on it (refer to the attached video). This problem does not occur on other pages, and I am unsure why...

I have provided a video for reference. Could someone please review my repository and see if they can identify any issues? VIDEO:

If necessary, here is the link to clone the repository: [email protected]:Angela-Inniss/CB.git

The website is currently hosted on Heroku: (work in progress).

I attempted to hide the menu on mobile by using display: none, but this resulted in hiding the entire menu.

Snippet of my JavaScript click functionality:

const dropDown = document.getElementById("nav-bar-grey");
const navBarOpen = document.getElementById("new-drop-down-js");
dropDown.onclick = showNav;
const closeButton = document.getElementById("closebtn");
closeButton.onclick = closeNav;

function showNav(event) {
    navBarOpen.classList.toggle("nav-open");
}

function closeNav(event) {
    navBarOpen.classList.toggle("nav-close");
}

Code snippet from about page mobile.html.erb:

<!--//mobile -->

<div class="background-about-mobile">
  <div class="white-bg-about">

    <h3>About.</h3>
    <div class="dash"> - </div>
    <h6>Who are we?</h6>

    <p class="about-text-mobile">We are a professional Carpet cleaning company that operates in the Leicestershire Region. Specialising in Carpet, Upholstery, hard floors, blinds and curtain cleaning fully insured, DBS Checked with 12 years plus experience.</p>
    <div class="dash"> - </div>
    <h6>What Services do we provide?</h6>

   <ul>
     <li>- Carpet cleaning</li>
     <li>- Rug cleaning</li>
     <li>- Stain removal</li>
     <li>- Amtico and Karndean maintenance</li>
     <li>- Hard Floor Maintenance</li>
     <li>- Curtains and blinds cleaning.</li>
    </ul>


  </div>

I expect the drop-down menu to only appear once clicked on, especially on mobile devices.

Answer №1

In order to update your javascript code effectively, you have two options:

If setting the height to 0px is not working as expected and making all child nodes visible, you can try using the following CSS code:

 .nav-close a{
   display : none;
 }

Alternatively, you can also use the below CSS code to achieve the desired result:

 #new-drop-down-js{
  display : none;  // set the default value as none
}

.nav-open{
  display :block !important;
}

.nav-close{
 display : none ;
}

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

Question about transparency - HTML, CSS, and Bootstrap

I adjusted the opacity of the bootstrap card to 0.8, but now I want the table to be opaque while the rest of the card remains translucent. How can I achieve this effect? I attempted to add the style opacity : 1 to the table, but it didn't have the des ...

Creating an HTML Table on the Fly

Is there a way to dynamically generate multiple HTML tables or ASP tables? I attempted the following code but it didn't work as expected. Table tb = new Table(); tb.ID = "tbl" + TBname; TableRow rowNew = new TableRow(); tb.Controls.Add(rowNew); for ( ...

Eliminate HTML nodes that are not currently visible

I am currently developing a Vue/Vuetify application that showcases a large number of images (10-20k) in a grid view along with some additional information. These images are grouped into different sections, and clicking on an image opens an overlay displayi ...

Proper method for verifying line-clamp in a Vue component

I came across a question that aligns perfectly with my current task - determining if text is truncated or not. The query can be found here: How can I check whether line-clamp is enabled?. It seems like my approach may not be accurate, so any guidance on ho ...

Encountering difficulties with implementing and utilizing bootstrap in Symfony 5.3 with Encore plugin

While I am currently dealing with an older version of Symfony, I decided to create a new 5.3 Symfony application from scratch. However, I am facing difficulties when trying to integrate bootstrap into it. After consulting some documentation, I proceeded to ...

Dealing with Error 462 in Excel VBA When Using Internet Explorer

This function is designed to loop through the hrefs obtained from the GetData() function, navigate each page, retrieve specific data, and then move on to the next one. Sub CreateDatabase() Dim ieNewPage As InternetExplorer, TableRows As Object, TableR ...

Monitoring alterations in dynamically produced input fields using jQuery

My code currently generates multiple input fields dynamically, each related to a specific database record. I utilize PHP's dynamic array notation ('[]') to store the input values. Everything is working smoothly up to this point... Now, I am ...

Discover the sub strings that fall between two specified regular expressions

I am looking for a way to extract substrings from a string that are between two specified regex patterns. Here are a few examples: My $$name$$ is John, my $$surname$$ is Doe -> should return [name, surname] My &&name&& is John, my & ...

What is the best way to measure the timing of consecutive events within a web browser, utilizing JavaScript within an HTML script tag?

Currently delving into the realm of JavaScript, transitioning from a Java/Clojure background, I am attempting to implement a basic thread-sleep feature that will display lines of text on the screen at one second intervals. Initially, I considered using t ...

Using ng-repeat in conjunction with ui-router conditions

Utilizing ui router ($routeprovider and $locationprovider) for angular js, I am looking to adjust the array being looped through in an ng-repeat based on the current url/route. Despite browsing similar threads on stack, I have not found a precise solution ...

Convert a web page to PDF with JavaScript when the user clicks on a button

Whenever the user clicks on the GeneratePDF button, the goal is to export the HTML page into a PDF file. The issue at hand is that although the HTML page is successfully exported into a PDF file after the first click, subsequent clicks do not result in dat ...

I encountered an error stating that ".then" is not defined during my attempt to save

Just starting out with node.js and I encountered an issue: TypeError: Cannot read property 'then' of undefined This is the code snippet causing the problem: router.post("/signup", (req, res) => { const userRegister = new UserRegister({ ...

The module 'PublicModule' was declared unexpectedly within the 'AppModule' in the Angular 4 component structure

My goal is to create a simple structure: app --_layout --public-footer ----public-footer.html/ts/css files --public-header ----public-header.html/ts/css files --public-layout ----public-layout.html/ts/css files In public-layout.html, the stru ...

Is there a way to decrease a field in a MongoDB database on a daily basis?

In the process of constructing an Angular2 application using MEAN stack architecture, I have a field called Remaining Days in my MongoDB database. I am interested in having this field automatically decrement by 1 each day. Do you know if this is possible ...

Retrieving data from a radgrid with the power of jQuery

Trying to extract the text from the label GetName in a radgrid using jQuery. Need to iterate through each record to check the value of the label. Can anyone provide assistance? Thanks! Below is the code for my radgrid. <telerik:RadGrid ID="Gridview1 ...

Nuxt issue: Vue router push not reflecting query updates

Recently, I encountered an issue with vue-router-query. When using a click event to navigate to the filter page and append the URL query to it, there seems to be a problem with updating the query data dynamically. The function responsible for sending the q ...

Troubleshooting the malfunctioning CSS Blend Mode

I'm eager to experiment with the CSS blend mode property, but I'm running into an issue where nothing seems to change when I apply the rules. Could there be something wrong in my implementation? I've set the isolation rule for the parent an ...

Having trouble retrieving attributes from Typed React Redux store

After scouring Google, official documentation, and Stack Overflow, I am still struggling to access my Redux store from a React functional component (written in Typescript). Despite following various guides, I keep encountering undefined errors. I can retri ...

What is the best way to transfer values from a nested child component up to the parent component

In my component hierarchy, there is a parent component with a child component that further contains another child component. Parent |-Child One (child of parent) |-Child Two (child of Child One) Currently, I am passing a value from Child Two to Child On ...

Tips for bringing in and adding an excel spreadsheet to a kendo grid with the help of JQuery

I am facing a challenge with my kendo grid as I am trying to incorporate an excel file into it. Specifically, I would like to import and add an excel file to my kendo grid. If, for instance, my kendo grid initially has 3 rows, after importing an excel file ...