Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

HTML5 Summary and Details / Polyfills

I've been learning some of the new features on HTML5 and was introduced to the <summary> and <details> tags. These are great, but they aren't compatible on all browsers (namely IE and Firefox).

The fix is to use a polyfill. However, I just completed the beginner javascript course, and the polyfill code I was able to find online was too complex for me at this point.

Does anyone have any resources for a simple javascript polyfill for just text? I basically have a heading and a paragraph underneath, the paragraph being the portion that I want to initially hide until clicking on the heading.

Not sure if this is helpful, but below is the code I used.

Here is the simple html:

<details>
<summary>I styled this to look like an h3    heading.
</summary>
<p>Detailed text.</p>   
</details>

Here is the styling:

summary {
    outline: none; 
    color:#4e6512;
    font-size: 16px; 
    font-weight: bold; 
    padding-bottom: 10px; 
    margin-bottom: 10px; 
}

summary::-webkit-details-marker {
   color:#4e6512; 
   background:#FFFFFF; 
}

details[open] summary::-webkit-details-marker {
 color:#809c38; 
 background:#FFF;
}

Any help would be appreciated!

Thank you!

(remember to include blank lines for formatting).

summary { outline: none; color:#4e6512; font-size: 16px; font-weight: bold; padding-bottom: 10px; margin-bottom: 10px; }

summary::-webkit-details-marker { color:#4e6512; background:#FFFFFF; }

details[open] summary::-webkit-details-marker { color:#809c38; background:#FFF; } 

1 Answer

Thanks, Iain.

I actually ended up finding a js download that works through: https://github.com/mathiasbynens/jquery-details