1

I am using jQuery to add a class of .display-product-noms to a div upon a certain menu item being hovered over. Once this triggers I then want a banner to appear but only if the previous class has been added to a div so i tried using the following:

if ($('.display-product-noms').css('left') === '16.4em!important') {
    $('.nav-banner').css( "left", "41em!important" );
}

but nothing happens, the banner stays out of view with its original value of left: -9999em; Can anyone shed some light on where i am going wrong?

user4349555
  • 123
  • 1
  • 12
  • Why do you need that? What is the real problem you need to solve? You chose bad way how to achieve that. – pavel Jan 13 '15 at 14:42
  • Please post a complete code example. – j08691 Jan 13 '15 at 14:42
  • I agree with panther. You are trying to achieve your goal in a very strange way. Have you tried just looking for the class name of the parents? Look at .parents(), .hasClass() methods. – Pavelloz Jan 13 '15 at 14:55

2 Answers2

0

http://jsfiddle.net/jadpLq73/1/

if ($('.product').css('left') == '10px') {
    alert($('.product').css('left'))
    $('.otherProd').css( "left", "10px", 'important');
}

Also read this: https://stackoverflow.com/a/8894528/3556874

div.style('color', 'blue', 'important');

this way you can define the !important priority

Community
  • 1
  • 1
Naeem Shaikh
  • 15,331
  • 6
  • 50
  • 88
0

Remove !important and use pixel, this is what css returns it is in px not in em so 16.4em = 262.399993896484px

enter image description here

console.log($('.display-product-noms').css('left'));
if ($('.display-product-noms').css('left') === '262.399993896484px') {
    alert("Chewbacca defense")
    //$('.nav-banner').css( "left", "41em!important" );
}
.display-product-noms{
    left: 16.4em!important
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class=display-product-noms />
Gildas.Tambo
  • 22,173
  • 7
  • 50
  • 78