I have three divs that are set to popup on li:hover using CSS. I want these divs to hover at the same level above their parent li regardless of the height of their content. In order to do so, I’m trying to use jquery to calculate the div’s height, then set a negative top value equal to the height of the div. Here’s what I have so far:
<script type="text/javascript">
$(document).ready(function() {
var pHeight = $('footer ul ul').height(); //Get height of footer popup
var nHeight = pHeight + "px"; //Calculate new top position based on footer popup height
$('footer ul ul').css({ //Change top position to equal height of footer popup
'top' : "-nHeight",
});
});
</script>
Firebug keeps telling me that there was an error parsing the value for top and the declaration was dropped. Any thoughts?
Change
'top' : "-nHeight",to
'top' : "-" + nHeightJavaScript does not parse variables inside of strings. I’ve also removed the
,since it’s redundant and it will produce an error in IE.