Reputation: 19
I am well aware that this is kinda of an idiot question,but I am rather new to JS and JQuery and how to link it to HTML code, but none of the similar threads lead to a solution.
By some miracle, I found and modified some JSFiddle code into this: https://jsfiddle.net/z7L2re8j/
Now, I'm trying to load JQuery from a CDN, and I also have a JS file with the functions to make the HTML (and CSS) work properly.
HTML's file head:
<html>
<head>
<meta charset="UTF-8">
<link rel="icon" href="images/icon.webp">
<link rel="stylesheet" href="./new.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"> </script>
<script type="text/javascript" src="./old.js"></script>
</head>
<body>
<!-- Html body -->
</body>
</html>
The files old.js
and new.css
are essentially the code that is written on the corresponding tabs in the JSFiddle link.
However, when I run the HTML code with the links as you see, it's not the same as the preview in JSFiddle. And I don't know what I am doing wrong.
So, am I doing the linking of the files correctly, and if not, what are my mistakes?
Thank you in advance
Upvotes: 1
Views: 3149
Reputation: 177786
If your question is how to link to old.js and new.css, look in the network tab and see where the browser is looking for them
To use CDN for jQuery and Bootstrap and get that information from a JSFiddle you can do this:
Right click on the links and open in new tab, you will see they are Bootstrap v3.3.7
Go to https://getbootstrap.com/docs/5.0/getting-started/introduction/ and get the latest or search google first for bootstrap CDN: I found for example https://www.bootstrapcdn.com/ and from there you can take the versions you want/need
Alternative since I can see your JSFiddle is not bootstrap 5 compatible:
https://blog.getbootstrap.com/2016/07/25/bootstrap-3-3-7-released/
$('ul.nav li.dropdown').hover(function() {
var first = $(this).find('.dropdown-menu')[0];
$(first).stop(true, true).delay(20).fadeIn();
}, function() {
$(this).find('.dropdown-menu').stop(true, true).delay(20).fadeOut();
});
$('ul.nav li#secondary').hover(function() {
console.log("reached sub here 1");
$(this).find('.sub-menu').stop(true, true).delay(20).fadeIn();
console.log($(this).find('.sub-menu'));
}, function() {
$(this).find('.sub-menu').stop(true, true).delay(20).fadeOut();
});
$('ul.nav li#third').hover(function() {
console.log("reached sub here 1");
$(this).find('.sub-menu').stop(true, true).delay(20).fadeIn();
console.log($(this).find('.sub-menu'));
}, function() {
$(this).find('.sub-menu').stop(true, true).delay(20).fadeOut();
});
$('ul.nav li#fourth').hover(function() {
console.log("reached sub here 1");
$(this).find('.sub-menu').stop(true, true).delay(20).fadeIn();
console.log($(this).find('.sub-menu'));
}, function() {
$(this).find('.sub-menu').stop(true, true).delay(20).fadeOut();
});
.navbar .sub-menu: before {
border-bottom: 7px solid transparent;
border-left: none;
border-right: 7px solid rgba(0, 0, 0, 0.2);
border-top: 7px solid transparent;
left: -7px;
top: 10px;
}
.navbar .sub-menu: after {
border-top: 6px solid transparent;
border-left: none;
border-right: 6px solid #fff;
border-bottom: 6px solid transparent;
left: 10px;
top: 11px;
}
.navbar-toggle {
z-index: 3;
}
nav.navbar i.fa {
padding-left: 5px;
padding-right: 5px;
}
ul.nav li:hover>ul.dropdown-menu {
display: block;
}
#navbar {
text-align: center;
}
.dropdown-menu .sub-menu {
left: 100%;
position: absolute;
top: 0;
display: none;
margin-top: -1px;
}
#navbar-collapse-new.navbar-collapse {
padding-top: 0px;
padding-right: 38px;
}
<!doctype html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous">
</script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</head>
<body>
<nav class="navbar navbar-default" role="navigation" aria-label="Main Menu">
<div class="container-fluid">
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="navbar-collapse-new">
<ul class="nav navbar-nav navbar-left" role="menu">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Villas <b class="caret"></b></a>
<ul class="dropdown-menu" id="secondaryMenu" role="menu" aria-expanded="false">
<li id="secondary" role="menuitem"><a href="#">1 Bedroom Villas</a>
<ul class="dropdown-menu sub-menu" role="menu">
<li id="tertiary" role="menuitem">
<a title="Fig Tree Villa" class="tertiary-link" href="/geonext/myhome.geo">Fig Tree Villa</a>
</li>
<li role="menuitem">
<a title="Mulberry Villa" class="tertiary-link" href="/geonext/myhome.geo">Mulberry Villa</a>
</li>
<li role="menuitem">
<a title="Grapevine Villa" class="tertiary-link" href="/geonext/myhome.geo">Grapevine Villa</a>
</li>
</ul>
</li>
<li id="third" role="menuitem"><a href="#">2 Bedroom Villas</a>
<ul class="dropdown-menu sub-menu" role="menu">
<li role="menuitem">
<a title="Bougainvillea Villa" class="tertiary-link" href="/geonext/myhome.geo">Bougainvillea Villa</a>
</li>
<li role="menuitem">
<a title="Margarita Villa" class="tertiary-link" href="/geonext/myhome.geo">Margarita Villa</a>
</li>
<li role="menuitem">
<a title="Oleander Villa" class="tertiary-link" href="/geonext/myhome.geo">Oleander Villa</a>
</li>
<li role="menuitem">
<a title="Violeta Villa" class="tertiary-link" href="/geonext/myhome.geo">Violeta Villa</a>
</li>
</ul>
</li>
<li id="fourth" role="menuitem"><a href="#">3 Bedroom Villas</a>
<ul class="dropdown-menu sub-menu" role="menu">
<li role="menuitem">
<a title="Jasmin Villa" class="tertiary-link" href="/geonext/myhome.geo">Jasmin Villa</a>
</li>
<li role="menuitem">
<a title="Lemoni Villa" class="tertiary-link" href="/geonext/myhome.geo">Lemoni Villa</a>
</li>
<li role="menuitem">
<a title="Mandarin Villa" class="tertiary-link" href="/geonext/myhome.geo">Mandarin Villa</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<a href="#" class="navbar-brand"> Contact Us</a>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
</body>
</html>
Upvotes: 1