Jessie Campbell Jessie Campbell - 5 months ago 8
jQuery Question

css method doesn't work with variable

var slidemenu_width = $('.inverse').css('width');
$('#slide-nav .navbar-toggle').css({'left':slidemenu_width + 'px'});


what's wrong with this code? I don't see the css been applied to my selector.

Answer

Try this example:

<div class="inverse" style="width:25px;"></div>
<div class="navbar-toggle"></div>

var slidemenu_width = $('.inverse').css('width');
$('.navbar-toggle').css('left',slidemenu_width); // add css like this