$(".rem").on('click', function(){
$(this).parent().remove();
})
$(".line").click(function(){
$(this).toggleClass("show");
})
$(parent).on('click', '.child', fn)
$(elem).on('click', '.rem', fn)
и $(elem).on('click', '.line', fn)
, где fn - ваши колбеки с remove()
и toggleClass()
display: inline;
$elem.on("click", handler);
$elem.on("keydown", handler);
function handler(event) {
if (event.type === "keydown") {
// ...
} else if (event.type === "click") {
// ...
}
// common functionality
}
Closures
This was fun! CodeSchool did a great job in Javascript Road Trip Part 3, but it just didn’t click for my son right away. Closures still trip me up to this day.
My first explanation attempt:
“A closure is like a dinosaur fossil — a snapshot from a moment in time preserved for millions of years. You can get still get information about the dinosaur from the fossil, even though the dinosaur itself has been gone for millions of years.”
Closures were starting to make sense, so I tried using cookies again . . .
“Let’s say I go to the same bakery every day and ask the baker for a cookie. The first thing he/she asks is, ‘What kind of cookie do you want?’ After a few days, the baker might already know what cookie I like and simply ask, ‘The usual?’. By saving my cookie choice in memory, he/she is able to reuse the same function from the previous day to get me the proper cookie without having to ask again.”
Eh… It was still a bit fuzzy, until my son asked me…
“So, it’s like when we go to the barber and he just cuts our hair without asking what we want? He always asks new customers how they want him to cut, but never asks us anymore.”
Ding, ding, ding! He got it!!!