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

how to run this function continuously?

var $bottom = $(".bottom").hide(); var $header = $(".header").hide();

$("button").click(function(){ $(".bottom").show(); $(".header").show(); $(".ui-icon-home").click(function(){ $(".apps").show("slow"); }); $("button").click(function(){ $(".screen").empty();

}); }); how to run this function continuously?

https://t.co/qkgdaTrgLa

1 Answer

Steven Parker
Steven Parker
230,248 Points

I'm not sure what you mean by "run continuously".

This code just attaches a click handler to the button element. But I see the handler will also set another handler when it runs. I'm not sure, but I suspect that the original handler would remain active and the second one attached with a new listener. If so, this might cause unexpected behavior. You might consider rewriting the outer handler to unbind itself using .off, or perhaps attach it originally using .one to avoid this.

I see your inner handler uses toggle so it might also be possible to install it (or a slightly modified version) as the only handler and avoid the use of the outer one completely.