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

Who likes quick and dirty events?

What are the benefits of quick and dirty event handlers?

3 Answers

Steven Parker
Steven Parker
229,644 Points

Who doesn't? The dirtier the better. :laughing:

But seriously, i'm not familiar with this term .. where did you hear of this? Is it in a course here? If so, please share the link to the course page.

Otherwise, what would distinguish a "quick and dirty" event or handler from any other?

Steven Parker
Steven Parker
229,644 Points

I see now, this is a comment from the instructor. She's talking about inserting handler code into the markup using an attribute.

I think she covers the benefits well right there in the course: quick, easy, and portable. I've used this technique myself on several occasions — but only when the handler code is a single statement or two. But this technique gets ugly pretty fast if the handler is more involved than that. Plus, it doesn't follow the "best practice" concept of separating your code from your markup. So generally this is a technique you might use mostly for testing and temporary experiments.

https://teamtreehouse.com/library/using-the-on-method

She's turned on() method into a quick an dirty event handler but then decided to stick it into javaScript.

Yeah I agree with you Steven, you don't want the handler to be too involved on quick and dirty events.