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

Can you treat a string of text as an array?

In this video it shows that you can treat a list of items as an array. I was just wondering if you can treat a string as an array?

For example if I had a <h1> element and I wanted each letter to individually slide up instead of the entire <h1> element itself how would I go about doing that?

Thanks

Craig

1 Answer

Steven Parker
Steven Parker
243,656 Points

Your script code can easily access individual letters in a string. But the browser doesn't consider them to be separate elements so you would not be able to apply different styling to them individually.

With a bit of work you could use your code to convert each letter into a new element and append it to the DOM, and then you could apply the individual styling.

by inserting each letter in between a span you mean?

Steven Parker
Steven Parker
243,656 Points

That would do it, then you could style each span element individually.