Nick
Nick

Reputation: 41

YUI 3 Getting height of an element and apply it to another element

I'm new to YUI and I'm finding it....strange compared to using jQuery for years. I can't seem to find out for the life of me on how to write something like this:

I'm trying to get the height of the div id #header and apply a margin-top with the value being the #header height to a div id called #noHero.

So the html markup would end up being something like:

<header id="header" />
<div id="noHero" style="height: HEADER HEIGHT" />

Hopefully someone can help me here.

Many thanks.

Upvotes: 0

Views: 115

Answers (2)

novomanish
novomanish

Reputation: 163

This should work:

Y.one('#noHero').setStyle('margin-top', Y.one('#header').get('region').height+'px')

Upvotes: 0

John Lindal
John Lindal

Reputation: 628

The gallery module dimensions provides totalHeight(), so you can do this:

Y.one('#noHero').setStyle('margin-top', Y.one('#header').totalHeight()+'px')

Upvotes: 1

Related Questions