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

I cant Strike the class when I add the new item to my restaurant list

when I add the class and code to turn of and off , the new list cant be "Strike". the order item of the list can be striked. see my code below: // 1. Hide/show the text inside the #helpText span element when the user's mouse passes over the text "How are these ranked?" (Hint: use the jQuery toggle() method) $("#helpText").hide(); $("#helpText").show(); $("#helpText").mouseover(function(){ $("p span").toggle(); }); // 2. Append a new restaurant to the restaurant list when the user enters a value into the #newRestaurant input and clicks on the #addNew button. const $list = $("<list><list>"); $("ul").append($list);

//input into restaurant list $("#addNew").click(function(){ var textInto = $("#newRestaurantInput").val(); $("list").text(textInto); });

// BONUS: Before appending the new restaurant to the list, use string concatentation to make sure the new restaurant name is surrounded by an opening and closing <li> tag.

// 3. Add the class "strike" to the restaurant name each time it's double clicked. Use event delegation on the ul element to listen for a click event on the ul's list items //$( "ul" ).addClass( "strike" ); $("ul > li").on('dblclick', function(event){ $(this).toggleClass("strike"); }); //BONUS: Refactor challenge 3 using the "this" keyword. //BONUS: Look up adi jQuery method that will let you toggle the .strike class on and off.

1 Answer

Your new list item uses a tag of <list> but your strike listener uses a tag of <li>. You could add a second listener

$("ul > list").on('dblclick', function(){
    $(this).toggleClass("strike"); 
});

but it's best to have consistency in list items

Thanks, I did it.