0

I'm setting an inline box-shadow style on a div.wrapper when a user clicks a #menu-open link. This overrides a default CSS style that is applied via the stylesheet. That is working.

However I also want to be able to remove that inline style when the user clicks the #menu-close link so that we then default back to the style in the CSS file.

I currently have the following;

<p id="menu-open">...</p>
<p id="menu-close">...</p>

<div class="wrapper">...</div>

<script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery('#menu-open').click(function(){
            jQuery('.wrapper').css('box-shadow', '0 0 3px rgba(0,0,0,0.75)');
        });
        jQuery('#menu-close').click(function(){
            jQuery('.wrapper').css('box-shadow', '');
        });
    });
</script>

I've also tried removeAttr('style'); and attr('style', ''); with no success.

3 Answers3

1

Try this.

jQuery('#menu-close').click(function(){
    jQuery('.wrapper').removeAttr('style');
});

Demo Fiddle

Rakesh Kumar
  • 2,705
  • 1
  • 19
  • 33
0

from jQuery 1.8+ you can simply use (crossbrowser) without using vendor specific prefixes.try this:

  jQuery('.wrapper').css({ boxShadow: '0 0 3px rgba(0,0,0,0.75)'});

for removing it,use:

  jQuery('.wrapper').css({ boxShadow: ''});

Working Demo

Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
0

Works fine here http://jsfiddle.net/7haVh/

You need to put your code inside ready:

jQuery(document).ready(function(){
jQuery('#menu-open').click(function(){
    jQuery('.wrapper').css('box-shadow', '0 0 3px rgba(0,0,0,0.75)');
});
jQuery('#menu-close').click(function(){
    jQuery('.wrapper').css('box-shadow', '');
});
});
Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231