show a division once it's clicked

I'm currently facing an issue with a script that I can't seem to solve on my own. Essentially, I am attempting to make a div appear after clicking on the "Products" button. Here is what I have so far:

   <div id="header">

    <div id="headcont"> 

            <div id="main-menu">
                <a href="#" id="button-products">Products</a>
            </div>

            <div id="products-menu">
                <a href="#">Jackleg units</a>
                <a href="#">Antivandal units</a>
                <a href="#">Storage containers</a>
            </div>

    </div>
</div>

and for the CSS:

    body{

    background-color:#666;

}

#header{
    position:absolute;
    top:0px;
    background-color: rgba(0, 0, 0, .9);
    width:100%;
    height:70px;
    border-bottom:1px #999 solid;
    padding:15px 0;
    z-index:200;
}

#headcont{
    overflow:hidden;
    width: 480px;
    margin: 0 auto;
}

#main-menu{
    margin-top:55px;
    float:right;
}

#main-menu a{
    display:block;
    width: auto;
    font-size:1.7em;
    float:left;
    margin: 0 10px;
    color:#eee;
}

#products-menu{
    overflow:hidden;
    background-color: rgba(255, 255, 255, .8);
    width:980px;
    display: none;
}

#products-menu a{
    display:block;
    width: auto;
    background-color:rgba(0, 0, 0, .6);
    padding: 5px;
    margin: 2px 5px 2px 0;
    text-decoration:none;
    font-size:1.7em;
    float:left;
    color:#eee;
}
  • the major thing - jquery:

    $(function() {
        $('#button-products').on('click', function() {
            $('#products-menu').css("display:","block");
        });
    });
    

To get a better idea of the issue at hand, you can view the example on JSFIDDLE: JSFIDDLE. Thank you in advance for your help.

Answer №1

There is a small error in your code that is preventing it from working properly. The issue lies with the colon at the end of the CSS property you are trying to set:

$('#products-menu').css("display:","block");
// Make sure to remove this extra colon

If you simply remove the colon, your code should work as expected. You can see the fixed version here: http://jsfiddle.net/7tbsR/4/

(It's also worth noting that jQuery was not selected in your fiddle, which may have contributed to the issue.)

Additionally, jQuery provides various methods for displaying hidden elements, such as .show() and different animation effects like fading or sliding items into view. If you're working with a menu, you might find .slideDown() to be a nice effect: http://jsfiddle.net/7tbsR/7/

Answer №2

When the user clicks on the "products-submenu" element, the "products-menu" element is displayed using jQuery's show() method. Alternatively, you can use fadeIn(600) for a smoother transition effect.

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

Swapping mouse cursor using JavaScript

Currently, I am working on a painting application in JavaScript that utilizes the Canvas Object. I would like to customize the mouse cursor when it hovers over the Canvas object. Can anyone advise me on how to accomplish this? ...

"Bootstrap - creating a dynamic effect with a repeating pattern overlay and vibrant background color in

I'm having trouble adding a repeating background image to my jumbotron that already has a rebecca-purple background color. I've tried multiple approaches, but can't seem to get it right. Here's the code snippet I'm working with: . ...

Having difficulty altering the div color in real-time using VueJS

I'm currently in the process of building an application with Bootstrap and VueJS. My goal is to create a folder structure similar to Google Drive, where I want to make a div stand out in blue once it's selected. Below is the code snippet: ex ...

obtain a link that is clickable from an array of options

$('button').on('click', function(){ let selection = document.getSelection().toString().trim(); document.execCommand('createLink', true, selection); }) <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery ...

Using Jsf to make an ajax request to retrieve real-time values through continuous polling

When the button is clicked, my ajax calls the managed bean method called yourFileData. Within yourFileData(), a new thread is created from the main thread. The goal is to execute the main thread on the first attempt while the new thread runs in the backgro ...

Is it necessary to convert SCSS into CSS in React?

I have a query about whether it is necessary to first compile our scss files into css and then import the css files into our react components, or if we can simply import the scss directly into the components? I've successfully imported scss directly ...

The dimension of HTML on an IOS web application

After successfully designing a web app that works well on desktop browsers and iPad Safari, I encountered an issue when trying to install it as a hybrid app using cordova 3.3.0. The problem arises with the height not displaying properly. Despite including ...

Revitalizing and rerouting page upon button click

The issue at hand is: When the "Post now" button is clicked, the modal with the filled form still appears. If the button is clicked again, it adds the same data repeatedly. I aim to have the page refresh and navigate to a link containing the prediction d ...

Certain visual elements fail to display properly within the web browser

I have a website with 5 pages (e.g. page1.html, page2.html, etc.), each having its own .css stylesheet. Oddly, some pages display images correctly while others do not. It seems like the issue might be with the specific pages or files, as using the same ima ...

Choose the option for overseeing safaris

Hello there! I need some help with Safari. Can you please guide me on how to disable the arrows? https://i.stack.imgur.com/1gzat.png ...

An alternate solution for achieving synchronous behavior in form submit button click event handling without using the async: false option

Operating with a login form is essential, and our current practice includes utilizing an AJAX call to validate information before proceeding with the login submission. Here is the existing code snippet being employed: (function ($) { var errorMessageH ...

Time for the browser to evaluate javascript code has arrived

We are looking to enhance the speed at which our Javascript files load in the browser. Although our own Javascript files are simple and small, larger libraries like jQuery and KendoUI take a considerable amount of time to evaluate. We are interested in fin ...

Assign the value selected from a dropdown menu to a PHP variable for MySQL

Is there a way to adjust the variable $Category in the following mysql query based on the selection made in the dropdown list? This seems like a straightforward task, but I'm having trouble figuring it out. It would be really helpful if the page coul ...

Tips for customizing the appearance of a disabled checkbox

I'm curious if you have any ideas on how to customize the appearance of a disabled checkbox? For example: <input type="checkbox" value="All Terrain Vehicle" name="exfilter_All Terrain Vehicle" id="exfilter_All_Terrain_Vehicle" ...

Parent menu fails to trigger the opening of child menu upon clicking

I'm struggling to modify a Wordpress theme to enable the child menus to expand when clicking on the parent menus. Is there a way to edit this code to make that functionality work? // Implement expandable menus var expand_link = $('<a class="m ...

ASP.Net listview that allows users to click on rows to highlight the selected item

Every row in my ASP.net list view is made up of multiple components enclosed in a <div>. I have a two-part question: How can I make these rows clickable to utilize the SelectedIndexChanged event and load data in another user control based on the ...

Sending a jQuery post using Ajax to a PHP validation script

Exploring new tricks and techniques, I am not using the form validation plugin with jQuery UI, but taking a different approach. A jQuery script posts a form to a PHP script via Ajax to validate the input and send a JSON-encoded string back. Based on the st ...

Share a URL and display small previews from it - php

Have you ever noticed that on certain websites, such as Facebook, when you post a link it automatically displays thumbnails from the linked website? Like in the image below: Ever wondered how to achieve that effect? ...

What is the best way to style the currently selected option element in a select dropdown?

I am trying to change the font color of specific option elements within a select dropdown by adding style="color: #D4D4D4". When I apply this style directly to an option element like <option value="TEST" style="color: #D4D4D4">TEST</option>, it ...

The functionality of the offcanvas button is not working correctly

I am currently utilizing the newest Bootstrap version of Offcanvas. Interestingly, there seems to be an issue with the close button functionality. When I click the "Add to Cart" button, the offcanvas displays properly. However, the "Add to Cart" button its ...