This forum is now read-only. Please use our new forums! Go to forums
9/14 - ol and not li?
Can someone tell me why we’re required to call the .selectable() function on ‘ol’ and not ‘li’?After all the effect is on the actual list items not the overall list, that is you click on an individual items and the effect impacts that individual item.
I’m just trying to get my head around how I determine the correct HTML tag to target to get the effect I’m looking for.
Thanks in advance.
Answer 54d69c0586f552cc880053f4
Answer 54d69da151b887a7c400598c
Consider:
<ol>
<li>one</li>
<li>two</li>
<li>three</li>
<li>four</li>
</ol>
and the JS,
$('ol').on('click','li',function(){});
Not the best example but it illustrates how any click within the OL will trigger the handler. Those click events will ‘bubble up’ to the parent element as a matter of course, so having the listener there rather than on the LI’s prevents propagation.
This topic (events, bubbling, propagation, delegation) is a tough one to explain without messing up, so it is recommended reading. Definitely follow up on this one.
1 comments
I’m learning a lot here, and will definitely take your advice of reading up on this. Thanks again, your help is appreciated.
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
1 comments
Thanks Roy, that does make sense now.