I've got a series of, what I'm calling stacks - within which will sit a h1
, h2
and some paragraph text. Each of these elements uses a data-style attribute that has the font family name as the value.
For instance:
<h1 data-style="arial">Heading 1</h1>
What I would like to do using jQuery; get the values of the elements within the stack, upon hovering the stack - so hovering each stack will reveal the fonts used on that particular stack. Then once I've got the information, place it for the user to see within an info panel.
Perhaps I'm going the long route on this one, I'm open to improving how I'm going about things. I am however majorly lost right now, it's time to ask for some help.
*ADDED a jsfiddle incase anyone wants a play: http://jsfiddle.net/62rG4/2/
My HTML:
<div id="font-info">
<h4>The follow fonts are used in this stack:</h4>
<p class="h1">h1:</p>
<p class="h2">h2:</p>
<p class="body">body:</p>
</div>
<div class="stack-1">
<h1 data-style="myfont">Heading 1</h1>
<h2 data-style="myfont">Heading two here</h2>
<p data-style="myfont">Hello world!</p>
</div>
<div class="stack-2">
<h1 data-style="myfont">Heading 1</h1>
<h2 data-style="myfont">Heading two here</h2>
<p data-style="myfont">Hello world!</p>
</div>
jQuery (so far)
var fontInfo = null;
function letsGetThisFont(){
var fontInfo = $.map($("h1,h2,p").attr("data","style"), function (el, i) {
return $(el).text();
});
joined = fontInfo.join(" ");
return joined;
}
$(".stack-1").hover(function(){
console.log(letsGetThisFont());
});