Javascript hover addclass not working after Ajax call - javascript

I created a menu and when you hover a child item, then some content will showing up.
The only problem is when after calling Ajax. It looks like the javascript is not working inside this Ajax call.
$.noConflict();
jQuery(document).ready(function($) {
$('.nav-menu li').hover(function() {
$(this).addClass('showcontentblock')
}, function() {
$(this).removeClass('showcontentblock')
});
});

You should put code you want to run after an Ajax call within the success, error or complete property of your Ajax method.
$.ajax({
type: 'post',
url: "www.url.com",
success: function (response) {
// Run code on success
},
error: function (error) {
// Run code on error
},
complete: function () {
// Run code no matter the outcome
$('.nav-menu li').hover(function() {
$(this).addClass('showcontentblock');
});
}
});

If the element(s) do not exist on page load or prior to the AJAX call you can bind event listeners using $(document).on and pass the selectors as the second argument. This replaces the legacy methods .live and .delegate
$.noConflict();
jQuery(document).ready(function($){
$('.nav-menu')
.on('mouseenter', 'li', function(){
$(this).addClass('showcontentblock');
})
.on('mouseleave', 'li', function(){
$(this).removeClass('showcontentblock');
});
});
I also agree that should be handled with CSS only.
.nav-menu li:hover {
// copy+paste showcontentblock styles
}
It seems like you're dynamically adding these menus. Try this pure CSS approach to the nav-menu.
.nav-menu {
background-color: #fff;
border-bottom: 1px solid #ddd;
display: sticky;
z-index: 1000;
}
.nav-menu li {
display: inline-block;
position: relative;
}
.nav-menu li.sub-menu:hover > .nav-items {
display: block;
}
.nav-menu li a,
.nav-menu li span {
color: #131313;
display: block;
padding: 15px 10px;
text-decoration: none;
}
.nav-menu li.sub-menu > span {
padding-right: 30px;
}
.nav-menu li.sub-menu > span:after {
content: "\f054";
font-family: "FontAwesome";
font-style: normal;
font-weight: 400;
font-size: 10px;
margin-top: 5px;
position: absolute;
right: 10px;
}
/* main navigation items */
.nav-menu > li.sub-menu > span:after {
content: "\f078";
font-family: "FontAwesome";
margin-top: 4px;
}
.nav-menu li a:hover,
.nav-menu li span:hover {
background: #eee;
}
.nav-menu .nav-items {
display: none;
}
.nav-items {
background: #fff;
border-radius: 3px;
box-shadow: 0 0 0 1px #e9e9e9, 0 1px 2px rgba(0,0,0, .1);
display: block;
left: 0;
list-style-type: none;
margin: 1px 4px 0 0;
padding: 0;
position: absolute;
width: 200px;
z-index: 9;
}
.nav-items li {
display: block;
}
.nav-items li a,
.nav-items li span {
display: block;
color: #131313;
padding: 10px;
}
.nav-menu .nav-items > li.sub-menu:hover > .nav-items {
display: block;
}
.nav-menu .nav-items .nav-items {
position: absolute;
left: 200px;
top: -1px;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.2/css/bootstrap.min.css">
<ul class="nav-menu">
<li>
<a href="">
Home
</a>
</li>
<li class="sub-menu">
<span>Solutions</span>
<ul class="nav-items">
<li>
Marketing
</li>
<li class="sub-menu">
<span>Products</span>
<ul class="nav-items">
<li class="sub-menu">
<span>Email Signatures</span>
<ul class="nav-items">
<li>
Compliance
</li>
<li class="sub-menu">
<span>Tracking</span>
<ul class="nav-items">
<li>
Analytics
</li>
<li>
GDPR
</li>
<li>
Reporting
</li>
</ul>
</li>
</ul>
</li>
<li>
Integrations
</li>
</ul>
</li>
</ul>
</li>
<li>Contact Us</li>
</ul>

Related

Navigation Menu Not Working on Big Cartel

I have a custom drop-down navigation menu that I want to use on my big cartel theme. It has HTML, CSS and Java Script.
Unfortunately, It is not working. The Java Script helps with the toggle event.
The drop-downs are on "Shop" and "About". When I click those dropdowns, they don't show.
In my Big Cartel Theme, I first tried linking to the JS file -- that didn't work.
I then put the script in the area and it still didn't work.
Here's the code working
https://codepen.io/findingcolors/pen/ZErZZgo
HTML
<div class="navigation">
<div class="nav-container">
<nav>
<div class="nav-mobile"><a id="nav-toggle" href="#!"><i class="fa-solid fa-bars"></i> Menu</a></div>
<ul class="nav-list">
<li>
Home
</li>
<li>
Shop <i class="fa-solid fa-angle-down"></i>
<ul class="nav-dropdown">
<li>
All Products
</li>
<li>
Stickers
</li>
<li>
Notepads + Sticky Notes
</li>
<li>
Bookmarks
</li>
<li>
Jewelry
</li>
<li>
Phone Straps
</li>
</ul>
</li>
<li>
About <i class="fa-solid fa-angle-down"></i>
<ul class="nav-dropdown">
<li>
The Brand
</li>
<li>
Shipping + Returns
</li>
<li>
FAQ
</li>
</ul>
</li>
<li>
Contact
</li>
<li>
Cart
</li>
<li>
Search
</li>
</ul>
</nav>
</div>
</div>
CSS
/* --- NAVIGATION bar --- */
.navigation {
height: 50px;
background: #fefcfc;
font-family: "Open Sans", sans-serif;
}
.nav-container {
text-align: center;
margin: 0 auto;
}
nav {
font-size: 16px;
text-transform: uppercase;
font-weight: bold;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
}
nav ul li {
float: left;
position: relative;
}
nav ul li a, nav ul li a:visited {
display: block;
padding: 0 20px;
line-height: 50px;
background: #fefcfc;
color: #716558;
text-decoration: none;
}
nav ul li a:hover, nav ul li a:visited:hover {
color: #90867a;
}
nav ul li ul li {
min-width: 250px;
}
nav ul li ul li a {
padding: 15px;
line-height: 20px;
}
.nav-dropdown {
position: absolute;
display: none;
z-index: 1;
text-align: left;
}
/* Mobile navigation */
.nav-mobile {
display: none;
position: absolute;
top: 0;
right: 0;
background: #fefcfc;
height: 50px;
width: 50px;
}
#media only screen and (max-width: 798px) {
.nav-mobile {
display: block;
}
nav {
width: 100%;
padding: 50px 0 15px;
}
nav ul {
display: none;
text-align: left;
}
nav ul li {
float: none;
}
nav ul li a {
padding: 15px;
line-height: 20px;
}
nav ul li ul li a {
padding-left: 30px;
}
.nav-dropdown {
position: static;
}
}
#media screen and (min-width: 799px) {
.nav-list {
display: inline-block;
}
}
#nav-toggle {
position: absolute;
left: -160px;
top: 10px;
cursor: pointer;
padding: 10px 35px 16px 0px;
color: #716558;
text-decoration: none;
font-size: 16px;
}
article {
max-width: 1000px;
margin: 0 auto;
padding: 10px;
}
Java
(function($) { // Begin jQuery
$(function() { // DOM ready
// If a link has a dropdown, add sub menu toggle.
$('nav ul li a:not(:only-child)').click(function(e) {
$(this).siblings('.nav-dropdown').toggle();
// Close one dropdown when selecting another
$('.nav-dropdown').not($(this).siblings()).hide();
e.stopPropagation();
});
// Clicking away from dropdown will remove the dropdown class
$('html').click(function() {
$('.nav-dropdown').hide();
});
// Toggle open and close nav styles on click
$('#nav-toggle').click(function() {
$('nav ul').slideToggle();
});
// Hamburger to X toggle
$('#nav-toggle').on('click', function() {
this.classList.toggle('active');
});
}); // end DOM ready
})(jQuery); // end jQuery
The jQuery library was missing from the website.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
After including it, the navigation menu is working now.

Add/Remove class when clicking on element with pure JavaScript

With a for loop, I removed the active class inside the a tag. However, when I want to add a class when clicking nothing happens and the class gets added to the li and a tag but without the active class name.
This has been asked so many times but I still cannot figure it out. Any help is appreciated. Thank you!
Here is the example: https://jsfiddle.net/fu5e7946/
Basically you are looping within your loop twice. I have fixed that.
You simply need to remove the previous active class and add new one like this:
document.querySelector(".sidenav a.active-list").classList.remove("active-list");
e.target.classList.add('active-list');
You can this: codepen:link https://codepen.io/emmeiWhite/pen/jOMZRxd
let elements = document.querySelectorAll('div, ul, li, a');
elements.forEach(i => {
i.addEventListener('click', function(e) {
document.querySelector(".sidenav a.active-list").classList.remove("active-list");
e.target.classList.add('active-list');
});
});
.sidenav {
width: 130px;
position: fixed;
z-index: 1;
top: 20px;
left: 10px;
overflow-x: hidden;
}
.sidenav ul {
background-color: black;
list-style: none;
padding: 0px;
padding-right: 0px;
}
.sidenav > ul > li {
color: white;
margin: 0px;
}
.sidenav a {
text-decoration: none;
font-size: 18px;
display: block;
line-height: 4em;
color: white;
background-color: black;
}
.sidenav a:hover {
color: grey;
}
.sidenav .active-list {
background-color: #e2c9be;
color: black;
}
<div id="active-buttons" class="sidenav" style="padding-top: 100px;">
<ul class="text-center">
<li>
Profile
</li>
<li>
Experience
</li>
<li>
Projects
</li>
<li>
Skills
</li>
</ul>
</div>
Try with toggle (more info: MDN). There you have working example:
let elements = document.querySelectorAll('div, ul, li, a');
elements.forEach(i => {
i.addEventListener('click', function() {
i.classList.toggle('active-list');
});
});
.sidenav {
width: 130px;
position: fixed;
z-index: 1;
top: 20px;
left: 10px;
overflow-x: hidden;
}
.sidenav ul {
background-color: black;
list-style: none;
padding: 0px;
padding-right: 0px;
}
.sidenav > ul > li {
color: white;
margin: 0px;
}
.sidenav a {
text-decoration: none;
font-size: 18px;
display: block;
line-height: 4em;
color: white;
background-color: black;
}
.sidenav a:hover {
color: grey;
}
div ul li a.active-list {
background-color: #e2c9be;
color: black;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="active-buttons" class="sidenav" style="padding-top: 100px;">
<ul class="text-center">
<li>
Profile
</li>
<li>
Experience
</li>
<li>
Projects
</li>
<li>
Skills
</li>
</ul>
</div>

Show active parent with matching submenu when page is loaded jQuery

I am working on a website where I am trying to achieve the following:
When the user clicks on a link, that link shall get an active status and the matching submenu shall become active also. When the user hovers over another link the active sub menu shall not be displayed. I have achieved that the current link is in an active status that matches the url but I can't get the matching submenu to show up. I don't know much about jQuery so I might I have stumbled upon the answer without knowing it. Here is some of the code as the website is currently on localhost.
HTML:
<div class="menu-container-portal">
<a class="toggle-menu" href="#" style="display: none;">
<img src="/images/18.612e0c6d167074c5746476/1542016024414/menu-icon.png" alt="Meny"></a>
<ul class="nav">
<li class="">
Upplev & Besök
<img class="arrow parent" src="/images/18.612e0c6d167074c57464a3/1542016024505/(2)%20(2)%2010897-200.png" alt="Underliggande">
<ul class="sub">
<div class="test1">
<li class="">
Bostäder
</li>
<li>
Evenemang
</li>
<li>
Kopia (1) av Upplev & Besök
</li>
<li>
Kopia (4) av Bostäder
</li>
<li>
Mat och dryck
</li>
<li>
Shopping
</li>
</div>
</ul>
</li>
<li>
Bo & Leva
<img class="arrow parent" src="/images/18.612e0c6d167074c57464a3/1542016024505/(2)%20(2)%2010897-200.png" alt="Underliggande">
<ul class="sub">
<div class="test1">
<li>
Bostäder
</li>
</div>
</ul>
</li>
<li>
Flytta hit & Jobba
</li>
<li>
Näringsliv
<img class="arrow parent" src="/images/18.612e0c6d167074c57464a3/1542016024505/(2)%20(2)%2010897-200.png" alt="Underliggande">
<ul class="sub">
<div class="test1">
<li>
Bostäder
</li>
</div>
</ul>
</li>
<li>
Kontakta oss
</li>
</ul>
</div>
CSS:
.menu-container-portal ul {
margin: 0;
padding: 0;
}
.active {
background: #2b90f5;
overflow: hidden;
}
.menu-container-portal li:hover>a {
color: #fff;
background: #304040;
opacity: .7;
}
.menu-container-portal li {
margin: 0;
padding: 0;
/*width: 100%;*/
height: 15%;
/*display: inline-block;*/
;
}
.menu-container-portal a {
text-decoration: none;
}
.menu-container-portal a:hover {
color: #dadcdf;
background: #304040;
padding-bottom: 10px;
}
/*.menu-container-portal {
max-width: 900px;
margin: 10px auto;
}*/
/*.menu-container-portal {
max-width: 900px;
margin-right: auto;
margin-bottom: 0px;
margin-top: 20px;
margin-left: 15px;
white-space: nowrap;
text-align:left;
} */
.menu-container-portal {
max-width: 1100px;
margin-right: auto;
margin-bottom: 0;
margin-top: 20px;
/* margin-left: 15px; */
white-space: nowrap;
text-align: left;
margin-left: 22.5%;
}
.toggle-menu {
display: none;
/*background: #404040;*/
padding: 10px 15px;
color: #fff;
}
.toggle-menu:hover {
opacity: 0.7;
}
.nav {
list-style: none;
*zoom: 1;
/*background:#404040;*/
display: flex;
justify-content: left;
}
.nav:before,
.nav:after {
content: " ";
display: table;
}
.nav:after {
clear: both;
}
.nav ul {
list-style: none;
width: 100%;
text-align: center;
}
.nav a {
padding: 10px 15px;
color: #101210;
*zoom: 1;
}
.nav>li {
float: left;
z-index: 200;
}
.nav>li>a {
display: inline-block;
}
.nav li ul {
display: flex;
position: absolute;
left: -99999px;
z-index: 100;
width: 100%;
/*height: 100%;*/
padding-bottom: 0.5em;
justify-content: left;
}
.nav li li a {
display: block;
/* display:inline-block; */
/*background: #404040;*/
/*position: relative;*/
z-index: 99999;
/*height: 100%;*/
width: auto;
/* width:100%; */
color: #fff;
}
.nav li li li a {
background: #404040;
/* z-index:200; */
;
}
.nav li {
/*position: relative;*/
;
}
.nav>li.hover>ul,
.nav>li.hover>ul :active {
left: 0;
overflow: hidden;
}
.nav li li.hover ul {
left: 100%;
top: 0;
overflow: hidden;
}
.arrow {
display: none;
}
.sub {
background: #304040;
opacity: 0.9;
}
ul .sub {
padding-top: 10px;
}
.menu-container-portal a:hover .nav li li li a {
background: #ff0000;
}
/* Bestämma undermenyns storlek */
.sub2 {
column-width: auto;
text-align: left;
}
.test1 {
display: inline-flex;
margin-left: 22.5%;
}
.test1-show {
display: block;
margin-left: 22.5%;
color: green !important;
}
jQuery:
$(function () {
setNavigation();
});
function setNavigation() {
var path = window.location.pathname;
path = path.replace(/\/$/, "");
path = decodeURIComponent(path);
$(".nav a").each(function () {
var href = $(this).attr('href');
if (path.substring(0, href.length) === href) {
/*$(".test1").addClass("active");
$('.nav a').filter(function(){
return this.href==location.href;}).parent()
.addClass('active').siblings().removeClass('active');
/*$(".nav > li > a").addClass("active");*/
$(document).ready(function () {
$('a(.active) a').hide();
$('a(.active)').hover(
function () {
$('.test1').hide();
},
function () {
$('.test1').show();
});
});
}
});
}
Hopefully that is all the code that is needed for you all to understand what I want and need some help with or some tips:) I think I got some of the jQuery code right I feel I am halfway there just the some little help :) thanks in advance :)
I was thinking about using one of these that I have found here:
http://jsfiddle.net/4G7TJ/1/
http://jsfiddle.net/MGkQC/7/
2019 - 01 - 21:
An update to my own post: I have come closer to my goal after alot of frustrating moments. But there is still one problem left I need to hide the submenu when I am hovering over another link here is the code so far:
jQuery:
$(document).ready(function() {
$(".nav li [href]").each(function() {
if (this.href == window.location.href) {
$(this).css("background", "red");
$(this).addClass("hover");
$(this).parent().find('ul.sub').css("left","0");
}
}); });
I was thinking about using .toggle somehow but cant really seem to get it working.
Intended you expecting the following functionality:
$("ul.nav > li > a").hover(
function(e) {
$('ul.nav > li > a.on-hover').removeClass('on-hover');
$(this).addClass('on-hover');
},
function(e){
//If you expecting to hide on-hover-out as well, uncomment the below line
//$('ul.nav > li > a.on-hover').removeClass('on-hover');
});
See in action: http://jsfiddle.net/kn761qgL/ and confirm.

On click, toggle a previously clicked icon back to it's original state

I have two drop down menus on a navigation bar, and have gotten the icons to toggle as long as that anchor is clicked, but i can not figure out how to get one to reset if a separate sub menu is clicked. I'm asking if there's a way to make this happen with how it is laid out now, and if not, how do i achieve this?
I'm also sorry in advance if this whole thing is littered with rookie mistakes.
I tried to condense the JSfiddle as much as possible, but you may need to expand the side part to see the affected icons to the right. I left out the responsive portion.
$(document).ready(function() {
$('.menu-toggle').click(function() {
$('nav').toggleClass('active')
})
$('ul li').click(function() {
$(this).siblings().removeClass('active');
$(this).toggleClass('active');
})
})
$("nav ul li a").click(function() {
$(this).find("i").toggleClass("fa-angle-down fa-angle-up");
});
body {
margin: 0;
padding: 0;
font-family: "Helvetica Neue", sans-serif;
background: url(img/sunset.jpg);
background-attachment: fixed;
background-position: center;
}
header {
position: absolute;
top: 0;
left: 0;
padding: 0 20px;
background: #000000;
width: 100%;
box-sizing: border-box;
}
.header-icons {
color: white;
}
header nav ul li a.active span {
color: red;
}
header nav {
float: right;
}
header nav ul {
margin: 0;
padding: 0;
display: inline-flex;
}
header nav ul li {
list-style: none;
position: relative;
}
.sub-menu {
color: fff;
}
header nav ul li ul {
position: absolute;
left: 0;
display: none;
}
header nav ul li.active ul {
display: block;
}
header nav ul li ul li {
display: block;
width: auto;
text-align: center;
}
header nav ul li ul li a {
background: linear-gradient(#000000, #34282C);
border-style: inset;
border-color: #000;
}
/*full screen header*/
header nav ul li a {
font-family: "Helvetica Neue", sans-serif;
height: 50px;
line-height: 50px;
padding: 0 20px;
color: #fff;
text-decoration: none;
display: block;
}
header nav ul li a:hover {
transition: .25s;
font-weight: ;
color: #000000;
background: #2196f3;
}
header nav ul li a.active {
background: #25383C;
font-weight: normal;
color: #fff;
}
header nav ul li a.active:before {
content: '\f096';
font-family: fontAwesome;
font-size: 25%;
position: absolute;
line-height: 50px;
bottom: 20px;
right: 2px;
color: #fff;
cursor: pointer;
}
.menu-toggle {
color: #fff;
float: right;
line-height: 50px;
font-size: 24px;
cursor: pointer;
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<head>
<title>Practice</title>
<link rel="stylesheet" type="text/css" href="CSS/style.css">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css">
</head>
<body>
<header>
<nav>
<ul>
<li><span class="header-icons"><i class="fas fa-pen-square fa-fw"></i></span>Services<span class="sub-menu"><i class="fas fa-angle-down fa-fw"></i></span>
<ul>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
</li>
<li><span class="header-icons"><i class="far fa-image fa-fw"></i></span>Portfolio<span class="sub-menu"><i class="fas fa-angle-down fa-fw"></i></span>
<ul>
<li>Link </li>
<li>Link </li>
<li>Link </li>
<li>Link </li>
</ul>
</ul>
</nav>
</div>
<div class="menu-toggle"><i class="fa fa-bars" aria-hidden="true"></i>
</div>
</header>
</body>
This is another solution just for your reference. I check for the active class under li tag, then remove or add the fa-angle-down or fa-angle-up class on i tag.
$('.menu-toggle').click(function(){
$('nav').toggleClass('active')
})
$('ul li').click(function(){
$(this).siblings().removeClass('active');
$(this).toggleClass('active');
// Check for active class
if($(this).hasClass('active')){
$(this).parent().find("i").removeClass("fa-angle-up").addClass("fa-angle-down");
}
$(this).find("i").toggleClass("fa-angle-down fa-angle-up");
})
https://jsfiddle.net/80wne34L/79/
Normally this is achieved by:
Make all arrows down.
Make clicked arrow up.
This function will work for you:
$("nav ul li a").click(function() {
// Cache variables (for speed)
var $this = $(this),
$arrow = $this.find('.sub-menu i');
// Make all arrows point down, excepted clicked arrow
$('.sub-menu i').not($arrow).addClass('fa-angle-down').removeClass('fa-angle-up');
// Toggle this arrow
$arrow.toggleClass("fa-angle-down fa-angle-up");
});
$(document).ready(function() {
$('.menu-toggle').click(function() {
$('nav').toggleClass('active')
})
$('ul li').click(function() {
$(this).siblings().removeClass('active');
$(this).toggleClass('active');
});
// Move into $(document).ready() for good practices
$("nav ul li a").click(function() {
// Cache variables (for speed)
var $this = $(this),
$arrow = $this.find('.sub-menu i');
// Make all arrows point down, excepted clicked arrow
$('.sub-menu i').not($arrow).addClass('fa-angle-down').removeClass('fa-angle-up');
// Toggle this arrow
$arrow.toggleClass("fa-angle-down fa-angle-up");
});
})
body {
margin: 0;
padding: 0;
font-family: "Helvetica Neue", sans-serif;
background: url(img/sunset.jpg);
background-attachment: fixed;
background-position: center;
}
header {
position: absolute;
top: 0;
left: 0;
padding: 0 20px;
background: #000000;
width: 100%;
box-sizing: border-box;
}
.header-icons {
color: white;
}
header nav ul li a.active span {
color: red;
}
header nav {
float: right;
}
header nav ul {
margin: 0;
padding: 0;
display: inline-flex;
}
header nav ul li {
list-style: none;
position: relative;
}
.sub-menu {
color: fff;
}
header nav ul li ul {
position: absolute;
left: 0;
display: none;
}
header nav ul li.active ul {
display: block;
}
header nav ul li ul li {
display: block;
width: auto;
text-align: center;
}
header nav ul li ul li a {
background: linear-gradient(#000000, #34282C);
border-style: inset;
border-color: #000;
}
/*full screen header*/
header nav ul li a {
font-family: "Helvetica Neue", sans-serif;
height: 50px;
line-height: 50px;
padding: 0 20px;
color: #fff;
text-decoration: none;
display: block;
}
header nav ul li a:hover {
transition: .25s;
font-weight: ;
color: #000000;
background: #2196f3;
}
header nav ul li a.active {
background: #25383C;
font-weight: normal;
color: #fff;
}
header nav ul li a.active:before {
content: '\f096';
font-family: fontAwesome;
font-size: 25%;
position: absolute;
line-height: 50px;
bottom: 20px;
right: 2px;
color: #fff;
cursor: pointer;
}
.menu-toggle {
color: #fff;
float: right;
line-height: 50px;
font-size: 24px;
cursor: pointer;
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<head>
<title>Practice</title>
<link rel="stylesheet" type="text/css" href="CSS/style.css">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css">
</head>
<body>
<header>
<nav>
<ul>
<li><span class="header-icons"><i class="fas fa-pen-square fa-fw"></i></span>Services<span class="sub-menu"><i class="fas fa-angle-down fa-fw"></i></span>
<ul>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
</li>
<li>
<a href="#">
<span class="header-icons"><i class="far fa-image fa-fw"></i></span> Portfolio
<span class="sub-menu"><i class="fas fa-angle-down fa-fw"></i></span>
</a>
<ul>
<li>Link </li>
<li>Link </li>
<li>Link </li>
<li>Link </li>
</ul>
</ul>
</nav>
</div>
<div class="menu-toggle"><i class="fa fa-bars" aria-hidden="true"></i>
</div>
</header>
</body>

superfish boostrap4 responsive

I try superfish with boostrap 4 and update for responsive using.
I inserted this code but it does'nt work well.
Do you have an idea to change the elements ?
Thanks
<style>
/*** ESSENTIAL STYLES ***/
.sf-menu, .sf-menu * {
margin: 0;
padding: 0;
list-style: none;
height:1.50rem;
}
.sf-menu li {
position: relative;
}
.sf-menu ul {
position: absolute;
display: none;
top: 100%;
left: 0;
z-index: 99;
}
.sf-menu > li {
float: left;
}
.sf-menu li:hover > ul,
.sf-menu li.sfHover > ul {
display: block;
}
.sf-menu a {
display: block;
position: relative;
}
.sf-menu ul ul {
top: 0;
left: 100%;
}
/*** DEMO SKIN ***/
.sf-menu {
float: left;
margin-bottom: 1em;
}
.sf-menu ul {
box-shadow: 2px 2px 6px rgba(0,0,0,.2);
min-width: 12em; /* allow long menu items to determine submenu width */
*width: 12em; /* no auto sub width for IE7, see white-space comment below */
}
.sf-menu a {
border-left: 1px;
border-top: 1px solid #dFeEFF; /* fallback colour must use full shorthand */
border-top: 1px;
padding: .75em 1em;
text-decoration: none;
zoom: 1; /* IE7 */
}
.sf-menu a {
color: #373a3c;
font-size: 13px;
vertical-align: middle;
}
.sf-menu li {
white-space: nowrap; /* no need for Supersubs plugin */
*white-space: normal; /* ...unless you support IE7 (let it wrap) */
-webkit-transition: none;
transition: none;
font-size: 13px;
height:30px;
}
.sf-menu ul li {
background-color: #eee;
}
.sf-menu ul ul li {
background-color: #eee;
}
.sf-menu li:hover,
.sf-menu li.sfHover {
/* background-color: #747474;*/
/* only transition out, not in */
-webkit-transition: none;
transition: none;
}
.backgroundSuperfish {
background-image: url(../images/menu_superfish.gif);
height:1.90rem;
}
.headerLine {
background-color: #FF0000;
height:0.05rem;
}
.current {
color:#fff;
font-size: 13px;
padding-left: 10px;
padding-top: 5px;
}
.current li:hover,
.current li.sfHove {
background-color: #FFEEC2;
color:#747474;
}
.subLevel {
color:#373a3c;
font-size: 13px;
padding-bottom: 5px!important;
}
.subLevel li:hover,
.subLevel li.sfHover{
background-color: #FFEEC2;
color:#747474;
}
.topLevel {
color:#373a3c;
font-size: 13px;
padding-bottom: 5px!important;
}
.topLevel li:hover,
.topLevel li.sfHover {
background-color: #FFEEC2;
color:#747474;
}
.imageheaderMenu {
}
</style>
html code with boostrap4
<div class="backgroundSuperfish">
<nav class="navbar">
<button class="navbar-toggler hidden-sm-up" type="button" data-toggle="collapse" data-target="#responsiveCollapse">☰</button>
<div class="collapse navbar-toggleable-xs" id="responsiveCollapse"> <!-- class .navbar-toggleable-* -->
<span class="pull-md-left">
<ul class="nav navbar-nav sf-menu" id="example">
<li class="nav-item current">Home
<ul>
<li class="nav-item topLevel"><span>Store</span></li>
<li class="nav-item topLevel"><span>Back Office</span></li>
</ul>
</li>
<li class="nav-item current">Configuration
<ul>
<li class="nav-item current subLevel"><span class="imageheaderMenu"><img src="/images/menu/configuration.gif" alt="" height="10" /> </span><span>My store</span>
<ul>
<li class="nav-item topLevel">General configuration</li>
<li class="nav-item topLevel">Laws & regulations</li>
</ul>
</li>
</ul>
</li>
</ul>
</span>
</div>
</nav>
</div>
the script with superfish
<script>
jQuery(function(){
jQuery('#example').superfish({
});
});
</script>

Categories