Attempting to conceal my default drop-down menu

I need to find a way to hide my drop down menu by default, as it currently shows up automatically. The drop down menu in question is under "My Account".

This is the HTML code I'm working with:

<li class="hoverli">
    <a  href="/customer/account">My Account</a>

    <ul class="user-account">
        <li><a href="">edit my account</a></li>
        <li id="wish"><a href="">my wishlist</a></li>
        <li id="gift"><a href="">my gift registry</a></li>
    </ul>
</li>

And here's the corresponding JavaScript:

<script type="text/javascript">
jQuery(function(){
    jQuery(".hoverli").hover(
      function () {
         jQuery('.user-account').slideDown('slow');
      }, 
      function () {
         jQuery('.user-account').slideUp('slow');
      }
    );
}); 
</script>

Answer №1

Include a new styling instruction

.website-user {
    visibility: hidden;
}

Alternatively, hide it upon page load using Vanilla JavaScript

window.addEventListener('DOMContentLoaded', (event) => {
  const websiteUser = document.querySelector('.website-user');
  websiteUser.style.display = 'none';
});

Answer №2

Is there a need for JavaScript when the same result can be achieved using CSS, like in these illustrated examples:

.user-account {
    display: none;
}

li:hover .user-account {
    display: inline-block;
}

If you desire animation :

.user-account {
    display: none;
    position: relative;
    top : -100%;
    transition: top 2s ease-in-out;
    z-index:0;
}

li:hover .user-account {
    display: inline-block;
    top : -100%;
}

Are there any specific advantages to using JavaScript in these scenarios?

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

Is it possible for the `drop-shadow` shadow to be applied only to certain elements?

In the top image below, you can see how the drop-shadow effect would be drawn if applied to the top element. I am exploring the possibility of having the shadow cast only on specific objects, as shown in the bottom image. I am open to unconventional solut ...

Transmit information to php script using an html document format

Is there a way to load the file table.php with the data that I am trying to pass when the ajax call is made? I have attempted to do this using the jquery.load method, where the second parameter is a data array, but it doesn't seem to be working. Here ...

Footer placement not aligning at the bottom using Bootstrap

I'm having trouble getting my footer to stay at the bottom of my website without it sticking when I scroll. I want it to only appear at the bottom as you scroll down the webpage. Currently, the footer is positioned beneath the content on the webpage. ...

Creating dynamic animations for your elements with AJAX

How can I apply animation to an element as soon as it appears? I want others with the same properties to remain unaffected. Here is my approach: $.each(data, function(i, obj) { if(obj['Ping'] == "FALSE"){ ...

Is there a way to obtain the ID of the submit button type?

I am wondering if it is possible to retrieve the value of a submit button's id without using JavaScript, as I need to insert these values into a MySql database. Below is the code snippet I have been working on: <form action="messages.php" method= ...

The AJAX call is not successful

I've encountered an issue while attempting to invoke a function on the server using AJAX. Interestingly, the request is successful for one URL but not for the other. Below is the snippet of code I am working with: $.ajax({ type: "POST", ...

Jquery's mouseclick event selects an excessive number of elements

Is there a way to retrieve the ID of an element when it is clicked, only if it has one? I currently have this code set up to alert me with the element's ID: $("[id]").click(function(event) { event.preventDefault(); var id_name = $(this).attr ...

Ways to include margin right for a table

Here is the HTML code I am working with: <table width="100%;> <tr><hr style="width:100%;"></hr></tr> <tr> <span style="float:left">abc</span> <span class="noindex" ...

Having issues with uploading an image through a popup form in PHP

I am facing an issue with a popup form that I am submitting using AJAX and PHP. Although the form is successfully submitted, the script is not uploading or inserting the picture name into MySQL. Interestingly, when I use the same script without the popup ...

Using AJAX to refresh and display content with jQuery

Seeking advice on dynamically refreshing and updating the content of a div that pulls information from an AJAX call. Currently, the div is cleared before new data is added upon click. I am looking for a way to achieve this update without relying on a click ...

Creating a custom Jquery function to generate a Div element instead of a Textbox in your web application

I need assistance with a jquery function that retrieves data from a JSON PHP MySQL setup. The retrieved results are currently displayed in textboxes. function showData(wine) { $('#Id').val(wine.id); $('#question').val(wine.question ...

Discovering all invisible divs within another div can be achieved by following these steps

Here's the HTML code I'm working with: <div id="main"> <div class="item">String</div> <div class="item">String</div> <div class="item">String</div> </div> Whenever a user clicks on any ...

Retrieve JSON information from within the Scope

In my JSON data, I have the following values: {"minmax":["0.01","67.00"]} I am trying to retrieve this data using jQuery in the following way: $.getJSON("../../dados/opcoesMinMax.json", function(data) { var getM ...

A step-by-step guide on enabling Autoclick for every button on a webpage

I am currently using Jquery and Ajax to carry out an action, my goal is for a code to automatically click on every button once the page has finished loading. Although I attempted to use the following javascript code to achieve this at the end of my page, ...

CSS "background-position: bottom" Less than ideal performance on Mobile Browsers

body { background-color: #000000; background-image: url('http://upload.wikimedia.org/wikipedia/commons/thumb/6/61/Aurigids_-_Jeremie_Vaubaillon.jpg/1280px-Aurigids_-_Jeremie_Vaubaillon.jpg'); background-repeat: no-repeat; background-attac ...

Adjusting the width of columns in a table

Previously in Bootstrap 3, I was able to use col-sm-xx on the th tags within the thead to resize table columns as needed. However, this functionality is no longer available in Bootstrap 4. How can I achieve a similar effect in Bootstrap 4? <thead> & ...

Customize hover effects for MuiCheckbox

For some reason, my checkboxes are displaying a circle on hover that I want to remove. https://i.sstatic.net/62TLL.png I attempted to make overrides in MuiTheme: export const MUI_THEME = createMuiTheme({ overrides: { MuiCheckbox: { root: { ...

Ensure the bottom div is anchored with a top margin

I am attempting to design a contact/information section at the bottom of my webpage, similar to the grey area at the bottom of this site. Here is my HTML code: *{margin:0; padding:0; box-sizing: border-box;} body{ padding-bottom: 0; } body .main{ marg ...

Always ensure that an element remains at the bottom during the sorting process

Currently, I have a list of items with an integer attribute that aids in sorting the list. However, I am looking for a way to designate specific items to always appear at the bottom of the list regardless of the sorting criteria. Is there a singular valu ...

The window failed to redirect to the intended URL provided by the Json response

function GetOpenUrl(transactionId, legacyIndication) { var json = { id: transactionId, legacyIndication: legacyIndication }; $.ajax({ type: "POST", url: "<%= Url.Action("OpenSa ...