Tom
Tom

Reputation: 845

jQuery Variable In Between Strings

I want to pass the following variable like so:

var $headerHeight = jQuery("#header").outerHeight() - jQuery("#header .main-menu").outerHeight();

jQuery(this).find('nav').attr('style', 'margin-top:' + $headerHeight + '!important');

It's obviously used in the wrong syntax; I just can't figure out how to use it correctly. The jQuery ".css" function isn't an option because it has to have the "!important" declaration. How can I pass $headerHeight in the above example?

Upvotes: 0

Views: 187

Answers (3)

Kevin B
Kevin B

Reputation: 95030

You're fixing the wrong problem. Instead of un-doing a change that slideToggle does, simply don't use slideToggle.

$(myelement).animate({
    height: "200px" // or whatever your target height is, calculated or static.
},500/*duration*/);

Upvotes: 0

Scorpio
Scorpio

Reputation: 1171

    var headerHeight = $("#header").outerHeight() - $("#header .main-menu").outerHeight();

    jQuery(this).find('nav').attr('style', 'margin-top:' +headerHeight+'px ' + '!important');

Upvotes: 1

SLaks
SLaks

Reputation: 887225

You need to add a unit to the property value. (probably px)

Upvotes: 0

Related Questions