I used live function before jquery 1.6. In jquery 1.7+, live function is not recommended, but using on function. I have a question with follow code:
$('#button').on('click', function(event) {
//add a new element to body
$('body').append('<div class="future">I am a new div</div>');
});
//bind a action to new element which is add a moment ago.
$('body').on('change', '.future', function() {
$(this).css({
'color' : 'red',
'font-weight' : 'bold'
});
$(this).text("on click me.");
$(this).on('click', {
name : 'liujun'
}, myhandler);
});
function myhandler(event) {
alert(event.data.name);
}
new action is not working,and syntax is correct. why?