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

Obtain the model value using Yii jQuery and then proceed to submit the form

Within the _form.php view, there is a presence of $model and a CActiveForm $form. I implemented JavaScript code to compare the value of $model->publication_date with the current date. If they are identical, the form will be submitted automatically. Othe ...

Show a stylish container when the server encounters an HTTP error with status code 500

My approach for error handling involves a straightforward ErrorHandler class structured like this: export class AppErrorHandler implements ErrorHandler { handleError(error : any){ //console.log('test error ', error.status); ...

iOS Simulator offers a range of both offline and online events for testing purposes

I have been working on a phonegap 3.3 application that incorporates angularjs. When testing the application in my browser, I am successfully able to detect and respond to 'offline' and 'online' events. However, when I switch to the ios ...

Using JQuery, retrieve all field values on click, excluding the value of the closest field in each row

I have a dynamic table where each row consists of an input field and a button. I am searching for a simpler way to select all input fields except the one in the current row when clicking the button in each row. All input fields have the same name and the r ...

Is it possible to achieve a callback with jQuery after loading?

Currently, I am working with PHP and jQuery and have successfully implemented the following code. $(".design").load("<?php echo get_bloginfo('url'); ?>/?addmod_ajax=1",{ menu: 'layout', }); This is my desired action. I woul ...

In order to design a v-btn-toggle with vertically aligned buttons, rather than horizontally

I'm currently in the process of developing a quiz using VueJS and Vuetify. My challenge lies in organizing the answer options vertically for the user to select. I attempted to utilize the v-btn-toggle component, but encountered an issue where the butt ...

When there is an absence of data, the jQuery datatable mysteriously van

I have encountered an issue in my Django app where a datatable used in the template disappears if there is missing data in any column or row. The problem occurs when trying to download the data in CSV, Excel, PDF, or copy format. Here is the HTML code snip ...

Executing database queries in a synchronous manner in JavaScript

let positionConfig = require('setting'); function retrieveConfig(element) { let setting; positionConfig.find({element: element}, function (err,docs) { console.log(docs[0].current); // show the value setting = docs[0].curr ...

What is the best way to automatically increase the value of another column in SQL when the primary key is set to auto

In my database, I currently have a table storing customer details. I am looking to introduce a new column that will provide either existing or new customers with a unique auto-incremented ID for identification purposes. Additionally, I require a primary ke ...

Can diverse array elements be divided into separate arrays based on their object type in JavaScript?

Looking to create new arrays based on objects with similar attributes from an existing array? Here's how: Starting with this [ {name: "test", place: "country"}, {name: "walkAndEat", Long: 100, Lat: 15, Location: "place name"}, {name: "te ...

Adjust the image to stretch and crop appropriately to perfectly fit the specified dimensions

I have a div with an image inside of it, and the overflow of the div is set to hidden so that the image will be cropped if it exceeds the width or height. It was working correctly, but sometimes it doesn't. What could be causing this issue? Here is th ...

What is the best way to position the label above the input text in a Material UI TextField component with a Start Adornment?

Struggling to figure out the right Material UI CSS class to style a reusable TextField component? You're not alone. Despite tinkering with InputLabelProps (specifically the shrink class), I can't seem to get it right. Here's the code snippet ...

Oops! The type in React.jsx is not valid - it should be a string for built-in components. You may want to consider converting your class component to a

The error message I am encountering is as follows: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it&ap ...

Browsing through a JSON document

Currently, I am attempting to extract schedule information from a JSON file called js/schedule.json. The format of this file is as follows: [ {"date":"12/06/2014","day":"Thursday","kick-off":"21:00","team1":"Brazil","team2":"Croatia","group":"A","stage":" ...

Iterate through the list retrieved from the backend

I have a list coming from the backend that I need to iterate through and hide a button if any element in the list does not have a status of 6. feedback The response returned can vary in length, not always just one item like this example with 7 elements. ...

Can you explain the meanings of <div class="masthead pdng-stn1"> and <div class="phone-box wrap push" id="home"> in more detail?

While working on styling my web pages with CSS and Bootstrap, I came across a few classes like "masthead pdng-stn1" and "phone-box" in the code. Despite searching through the bootstrap.css file and all other CSS files in my folders, I couldn't find a ...

Modify the background color of a particular TD element when clicking a button using JavaScript and AJAX

When I click on the "Active account" button inside the designated td with the <tr id="tr_color" >, I want the value "1" to be added to the 'active_account' column in the database. I have been successful with this functionality. However, I a ...

i18next backend failing to load files

Hey there! Currently, I am implementing i18next within my Node JS Application. Below is the configuration code for i18next: const i18nextBackend = require('i18next-node-fs-backend'); i18n .use(i18nextBackend) .init({ fallbackLng: &apos ...

Error occurred while looking for user by ID in the everyauth

I previously had a working example with express 2.*, but now I am transitioning to version 3.*. The issue arises during authentication with Facebook, causing some problems. Everything works fine until everyauth makes the GET request to Facebook and then re ...

Learn how to create a PHP activity feed that functions like Facebook, and discover the best methods for converting JSON responses into HTML

We are currently working on a website that functions similarly to Facebook, specifically focusing on the activity feed. To load the user's activity feed, we use AJAX to send a request to a PHP file which then processes the logic and returns the values ...