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
Hemed Al tiwani
3,658 PointsWhat is the data-role?
Hi, I expect inside a tag to be something like ids classes but I see these (data-role, data-position . . .) is this part of html language?
3 Answers
Kevin Korte
28,149 PointsIt's really part of javascript, but the data attribute allows us to store information about element. It's kind of a handy way to pass information out of a database, into javascript.
If you're using jquery, you can get the value of a data attribute using .data()
So if I had <div class="box" data-role="presentation">The box</div> I could call var el = $('.box').data('role'); and than if you were to console.log(el); it would return presentation as the value.
Just be aware, this is a very insecure way to pass data around. Never rely on this for user permissions, roles, passwords, or anything authenticating wise. Not only can it be seen by anybody or user of your site, the value of the data attribute can manually be changed by a user.
Cindy Lea
Courses Plus Student 6,497 PointsIt may be JQuery, but it goes in your HTML file.
Hemed Al tiwani
3,658 PointsThank you all guys.