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 JavaScript and the DOM (Retiring) Responding to User Interaction Event Bubbling and Delegation

Why 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
Yu-Che Hung
Courses Plus Student 10,607 Points

I 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.)

"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

I have no idea why your comment was -4 when I saw it. I upvoted it because it seems totally reasonable.

Because 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.