Starting with some DOM elements in the nested structure below, you assign listeners for the same event to a child element and one of the parents using the JavaScript that follows. You want to ensure that when '.leaf' is clicked, only its event handler will be fired, instead of the click bubbling up and also firing the parent's click handler. What do you need to add to its handler function?html Item 1 Sub Item 1 Sub Item 2 js$('.leaf').click(function (event) { console.log('Sub Item 1 got a click');});$('#main-menu').click(function (event) { console.log('Main menu got a click');});

🎲 Try a Random Question  |  Total Questions in Quiz: 75  |  🧠 Study this quiz with Flashcards
This question is part of a full practice quiz:
jQuery Quiz — practice the complete quiz, review flashcards, or try a random question.

jQuery MCQs For LinkedIn Skill Assessments.


Starting with some DOM elements in the nested structure below, you assign listeners for the same event to a child element and one of the parents using the JavaScript that follows. You want to ensure that when '.leaf' is clicked, only its event handler will be fired, instead of the click bubbling up and also firing the parent's click handler. What do you need to add to its handler function?<br>html<br><ul class='items' id='main-menu'><br> <li><br> Item 1<br> <ul><br> <li class='leaf'>Sub Item 1</li><br> <li>Sub Item 2</li><br> </ul><br> </li><br></ul><br><br>js<br>$('.leaf').click(function (event) {<br> console.log('Sub Item 1 got a click');<br>});<br>$('#main-menu').click(function (event) {<br> console.log('Main menu got a click');<br>});<br>