Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
7
rated 0 times [  8] [ 1]  / answers: 1 / hits: 17871  / 9 Years ago, fri, may 22, 2015, 12:00:00

Trying to mix a variable with :not then use that variable with addClass. but no luck yet.



HTML



<ul>
<li><a href=#>Nav One</a></li>
<li><a href=#>Nav Two</a></li>
<li><a href=#>Nav Three</a></li>
<li><a href=#>Nav Four</a></li>
</ul>


LESS



ul{
li{
a{
color: black;
transition: all 0.5s ease;
font-size: 3rem;
text-decoration: none;
}
}
}
.enc-non-active{
color: gray;
}


JAVASCRIPT



myFunction('ul li a', 'enc-active', 'enc-non-active');

function myFunction($menu, $activeClass, $nonActiveClass) {
$(function(){
$($menu).hover(function(){
$(this).addClass($activeClass);
},
function(){
$(this).removeClass($activeClass);
});
$($menu).hover(function(){
var fullPath = $menu + ':not(' + $activeClass + ')';
$(fullPath).addClass($nonActiveClass);
},
function(){
var fullPath = $menu + ':not(' + $activeClass + ')';
$(fullPath).removeClass($nonActiveClass);
});
});
}


Here is the CodePen http://codepen.io/antfuentes87/pen/pJEaeb if anyone can let me know what I am doing wrong, that would be great. Thanks for your time.


More From » jquery

 Answers
38

You forgot a dot in :not(. - easily fixed http://codepen.io/anon/pen/zGKRyW



var fullPath = $menu + ':not(.' + $activeClass + ')';
$(fullPath).addClass($nonActiveClass);

[#66505] Wednesday, May 20, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
freddiem

Total Points: 456
Total Questions: 116
Total Answers: 101

Location: Dominica
Member since Mon, Jan 4, 2021
3 Years ago
;