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 trialWill Powers
6,612 PointsWhy use the <div> instead of <ul>?
In this video, Guil uses the <div> element to show how bubbling works. He says for performance reasons it is good to select an element close to the actual target. He uses the <div>, but there is an <ul> element one level closer to the <li>s.
What are some reasons to prefer using the <div> instead of the <ul>?
3 Answers
Yu-Che Hung
Courses Plus Student 10,607 PointsI think that's because he already set a class for the <div> "listDiv" so that he doesn't have to re-do the process again( select the target, addEventListener...etc.)
Marco Fregoso
379 Points"div" elements are usually used for styling purposes in the closer future with help of CSS. Several parts of a document can be wrapped inside a div for example and then give it a certain class; for example "container" and then apply certain styles to that div's class, as I said this is just the best practice it seems and this helps to organize your code in a more cleaner and meaningful way in both your HTML and CSS files. Hope it helps, and if I'm wrong I'd be glad to know :) as I'm also currently learning
Sam Allen
7,176 PointsI have no idea why your comment was -4 when I saw it. I upvoted it because it seems totally reasonable.
Axel Perossa
13,930 PointsBecause it doesn't have anything to do with the answer. Marco is talking about the general meaning of a div element and its uses (correctly), but the question is about something else, very specific to this particular code example. The downvotes come off a bit mean though.
Itzhak Dangoor
Full Stack JavaScript Techdegree Student 4,077 PointsWill have a good question, does anyone have a good answer? Thank you