Using JQuery to Customize Navigation Menu Targeting

On my website, I am trying to make an href button and a menu fade in as the page loads. However, I am struggling to find the correct code due to its placement within multiple tags, especially since I am new to JS and JQuery. I have provided a fiddle with all the code included.

Here is what I have accomplished so far:

HTML:

<div id="ImageMain">

<ul id="nav">
    <li id="navm"><a href="#">Men</a></li>
    <li id="navm"><a href="#">Women</a></li>
    <li id="navm"><a href="#">Contact</a></li>
</ul>

<a href="#" id="homeb">Shop Now</a>

</div>

<script>    
$(document).ready(function() {
    $("#navm").fadeIn(500);
});
$(document).ready(function() {
    $("#homeb").fadeIn(500);
});
</script>

CSS:

#ImageMain {
background-image: url(http://juliapavel.de/wp-content/uploads/2016/07/DSC1139-1.jpg);
background-repeat: no-repeat;
background-size: cover;
height: 1400px;
text-align: center;
color: black;
margin-right: auto;
margin-left: auto;
padding-top: 0px;
position: relative;
}

#ImageMain h1 {
padding-bottom: 10px;
padding-top: 450px;
}

#homeinfo {
padding-bottom: 15px;
}

#brand {
float: left;
padding: 100px;
}

#Pronto {
width: 150px;
}

#ImageMain #brand a {
font-size: 20px;
transition-duration: 1s;
}

#nav #navm a {
transition-duration: 1s;
}

#brand a:hover {
opacity: .3;
transition-duration: 1s;
}

#navm a:hover {
opacity: .3;
transition-duration: 1s;
}

#navm {
margin-right: auto;
margin-left: auto;
display: none;
}

#homeb {
text-decoration: none;
color: black;
border-radius: 5px;
border: solid 1px black;
padding: 12px;
transition-duration: 1s;
}

#wrapper a {
text-decoration: none;
border: solid 1px #141414;
border-radius: 5px;
padding: 10px;
color: #141414;
}

#homeb:hover {
opacity: .3;
transition-duration: 1s;
}

#wrapper a:hover {
opacity: 0.7;
transition-duration: 0.8s;
}

h3 {
color: white;
}

#nav {
list-style: none;
padding: 0;
padding-top: 5px;
text-align: center;
}

#nav li {
display: inline-block;
padding: 7px;
}

#nav a {
text-decoration: none;
color: black;
font-size: 15px;
}

https://jsfiddle.net/tux41Lvp/

Answer №1

To make the button anchor work properly, you must enclose it in a parent div:

<div id="link">
    <a href="#" id="homeb">Shop Now</a>
</div>

Next, you need to ensure that the target elements are hidden (make sure to target their parents):

#nav{ display:none;}
#link{ display:none;}   

Refer to the JavaScript code snippet for implementation details:

$(document).ready(function() {
            $("#nav").fadeIn(500);
            $("#link").fadeIn(1000);
        });

Additionally, here is some CSS code to style the different elements on the page:

#ImageMain {
background-image: url(http://juliapavel.de/wp-content/uploads/2016/07/DSC1139-1.jpg);
/* Other styles */
}

#brand {
/* Styling for brand element */
}

/* More CSS styling rules */

#wrapper a {
/* Styling for wrapper anchor */
}

h3 {
color: white;
}

Finally, include the necessary HTML markup with the script tag at the end:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="ImageMain">

<ul id="nav">
<li id="navm"><a href="#">Men</a></li>
<li id="navm"><a href="#">Women</a></li>
<li id="navm"><a href="#">Contact</a></li>
</ul>

  <div id="link">
    <a href="#" id="homeb">Shop Now</a>
  </div>


</div>

Answer №2

Ensure to conceal the items first before revealing them, as having two distinct items with similar IDs is not allowed, hence I adjusted the selector.

$("#nav a, #homeb").hide();
$(document).ready(function() {
    $("#nav a").fadeIn(1000);
    $("#homeb").fadeIn(1000);
});
#ImageMain {
background-image: url(http://juliapavel.de/wp-content/uploads/2016/07/DSC1139-1.jpg);
background-repeat: no-repeat;
background-size: cover;
height: 1400px;
text-align: center;
color: black;
margin-right: auto;
margin-left: auto;
padding-top: 0px;
position: relative;
}

#ImageMain h1 {
padding-bottom: 10px;
padding-top: 450px;
}

#homeinfo {
padding-bottom: 15px;
}

#brand {
float: left;
padding: 100px;
}

#Pronto {
width: 150px;
}

#ImageMain #brand a {
font-size: 20px;
transition-duration: 1s;
}

#nav #navm a {
transition-duration: 1s;
}

#brand a:hover {
opacity: .3;
transition-duration: 1s;
}

#navm a:hover {
opacity: .3;
transition-duration: 1s;
}

#navm {
margin-right: auto;
margin-left: auto;
display: none;
}

#homeb {
text-decoration: none;
color: black;
border-radius: 5px;
border: solid 1px black;
padding: 12px;
transition-duration: 1s;
}

#wrapper a {
text-decoration: none;
border: solid 1px #141414;
border-radius: 5px;
padding: 10px;
color: #141414;
}

#homeb:hover {
opacity: .3;
transition-duration: 1s;
}

#wrapper a:hover {
opacity: 0.7;
transition-duration: 0.8s;
}

h3 {
color: white;
}

#nav {
list-style: none;
padding: 0;
padding-top: 5px;
text-align: center;
}

#nav li {
display: inline-block;
padding: 7px;
}

#nav a {
text-decoration: none;
color: black;
font-size: 15px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="ImageMain">

<ul id="nav">
    <li><a href="#">Men</a></li>
    <li><a href="#">Women</a></li>
    <li><a href="#">Contact</a></li>
</ul>

<a href="#" id="homeb">Shop Now</a>

</div>

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

Eliminate operation in React with the help of Axios

Within my React application, I have implemented a callback method for deleting data from an API using the axios library: deleteBook(selectedBook) { this.setState({selectedBook:selectedBook}) axios.delete(this.apiBooks + '/' + this.select ...

Import the complete JSON file into a variable as an array

I am struggling with loading an external json file (locations.json) into a variable and then using the information found here: http://www.json.org/js.html Despite trying various methods, I have not been successful in populating the variable. Even after fo ...

What is the best way to delete the onclick event of an anchor element?

Struggling to remove the onclick attribute using jQuery? Here's my code: function getBusinesses(page){ if(page==0){ alert("you are already on First Page"); $("#previous a").removeAttr("onclick ...

What is the reason behind the change in size and shape of the text when using "overflow: hidden"?

Check out this interactive demo using the provided HTML and CSS: You can view the demo by clicking on this link. /*CSS*/ .header { margin: 0px; padding: 0px; width: 100%; } .headertable { padding: 0px; margin: 0px; width: 100%; border-sp ...

Is it possible to submit a POST method without using a form?

I am looking to create a button that functions similar to the "Follow" buttons found on social networks. The challenge I face is that I need to refresh the page when the user clicks the button, as the content of the page heavily depends on whether the user ...

Using shadow effects on the <Grid> component with Material UI

Is there a way to implement the box-shadow property on a <Grid> component in Material UI? I've gone through the official documentation regarding Shadows - Material UI, but I'm struggling to grasp how it can be applied to a <Grid>. De ...

Keep the music playing by turning the page and using Amplitude.js to continue the song

I have implemented Amplitude.js to play dynamic songs using a server-side php script. My objective is to determine if a song is currently playing, and if so, before navigating away from the page, save the song's index and current position (in percenta ...

Modifying an object's label based on a particular value using JavaScript

In my current project involving React.js charts, I am looking to organize data by month. In Django, I have set up a view to display JSON containing the total events per month in the following format: [ { "month": "2022-06-01T00:00:0 ...

The Selenium Action class is failing to perform a second mouse hover on the same web element

Actions action = new Actions(Driver); action.MoveToElement(webelement).ClickAndHold().Perform(); The code snippet above is used to perform a mouse hover on a Web Element, and it works perfectly the first time. However, when attempting to do the mouse hove ...

(Discord.JS) Bot failing to send direct message upon user joining the server

When attempting to send a DM message, I am using the following code: bot.on('guildMemberAdd', (member) => { member.send('a'); }); I am experiencing difficulty in understanding why the private message is not being successfully se ...

The message "jest command not recognized" appears

My test file looks like this: (I am using create-react-app) import React from 'react'; import ReactDOM from 'react-dom'; import App from './components/Calculator'; import { getAction, getResult } from './actions/' ...

Determining the dimensions of a div with a scrollbar using Jquery

Is there a way to get the width and height of a div with scroll that includes both visible and hidden content using JQuery? If anyone has a solution for getting these values, please share. <div id="area" class="divLeftCem area"> <div id="pan ...

How come the dark grey in CSS appears to be lighter than the standard grey hue?

JSBIN DEMO Could this be a mistake or is it a bug? Shouldn't the dark gray shade be darker than the default grey one? HTML <div class="lightgrey">Light Grey</div> <div class="grey">Grey</div> <div class="darkgrey">Dar ...

Will a notification box appear upon submission indicating success or failure?

After the submit button is clicked, I need a pop-up box to display either a successful or failed message. Then confirm the message by clicking OK. Currently, I am seeing an "undefined" pop-up followed by a failed message pop-up. Can someone please assist m ...

Updating HTML label values using jQuery in a loop based on their index position

I am having an issue with my ajax call where I want to loop through each label in a class and set their value to the response returned from the server. However, the current code sets all labels to the same value instead of setting individual values based o ...

Transform a section of text into JSON format to utilize in DataTables

Currently, I am utilizing DataTables and Leaflet in my project. The data displayed below needs to be represented on my screen using Datatables. Specifically, I would like to convert it into JSON format without including the {....} part. How should I proc ...

Transforming JSON data into an HTML template

Incorporating Angular 6 in my project, I have come up with the following templates: Header, Left panel, Body part, Footer Header, Left panel, Body part, Right panel, Footer Header, Body part, Footer Considering the numerous templates, I am aiming to tran ...

Issue with passing parameter values in MVC Html.ActionLink

Currently, I am experimenting with MVC for a demonstration and have managed to put together some components. However, I am encountering difficulties with an Html.ActionLink. The goal is to display a series of dropdown lists to the user that must be selecte ...

Filtering data from an Ajax request in Angular using a filter function with JSON

Hi everyone, I recently started learning AngularJS and created a basic item list with search functionality and pagination. Everything was working smoothly, so I decided to move my list outside the controller and store it as a JSON file. Here's what ...

Whenever I run "npm run build-dev" in Webpack with JavaScript, the browser continuously refreshes

I've been working on familiarizing myself with webpack lately. I've managed to convert everything to load modules and plugins, and it's all working fine when I use "npm run build-prod". Even when I use liveServer, the HTML loads properly. Ho ...