[jQuery] Do object events persist in cloning? I can't get this method to work.
What I'm doing is creating a couple button objects and cloning them.
Here is my code:
$(document).ready(function() {
$.fn.addOne = function() {
return this; // This will do stuff once I get it it to be
called
}
$.fn.removeOne = function() {
return this; // as will this
}
var memberSections = $('form .member-sections');
var youngerSections = $('form .younger-sections');
var minus = $('<a>')
.attr('href', 'javascript:;')
.addClass('minus')
.addClass('button')
.click(function() {
console.log('Hello');
// $(this).parent().parent().removeOne();
});
var plus = $('<a>')
.attr('href', 'javascript:;')
.addClass('plus')
.addClass('button')
.click(function() {
console.log('Hello');
// $(this).parent().parent().addOne();
});
var toggler = $('<div>')
.addClass('toggler')
.append(minus)
.append(plus);
$(memberSections).prepend(toggler.clone());
$(youngerSections).prepend(toggler.clone());
});
Why is it that neither button logs to the console when clicked?
Thomas