jquery on вместо live

kvins
На сайте с 23.08.2011
Offline
95
1449

Подскажите что я делаю не так

Раньше с live функцией я мог действовать на обьекты которые подгружаются через js

Когда я пытаюсь в новой версии jquery обратится к обьекту вновь загруженому то нече не пашет

Вот код

$(".areagone").on('click', this, function(){

$(this).animate({height:130},500);
});
Магазин уникальных статей. (http://linkum.ru/to/13254/)
siv1987
На сайте с 02.04.2009
Offline
427
#1

this - чей? .areagone элемент загружен?

$(document).on('click', '.areagone', function(){

....

});

document - желательно заменить на контейнер куда загружается динамический html

speed-core
На сайте с 30.03.2014
Offline
33
#2

live - работает даже когда DOM не постоянный.

on - работает с уже загруженным DOM. Можете передать JS в месте с кодом. Как вариант

HOST-PROTECTION (/ru/forum/848747), профессиональный web хостинг, гарантия стабильности, защита от DDoS.
siv1987
На сайте с 02.04.2009
Offline
427
#3
speed-core:
on - работает с уже загруженным DOM.

какбэ да, но он может работать и как delegate.

live частный случай $(document).on(event, selector ...)

JQuery:

When a selector is provided, the event handler is referred to as delegated. The handler is not called when the event occurs directly on the bound element, but only for descendants (inner elements) that match the selector. jQuery bubbles the event from the event target up to the element where the handler is attached (i.e., innermost to outermost element) and runs the handler for any elements along that path matching the selector.
[Удален]
#4

siv1987, к сожалению конструкции вида

$(".class").on(function(){},function(){});

не возможны :(

siv1987
На сайте с 02.04.2009
Offline
427
#5

$(loaded element|document).on(string event, string selector, function handler);

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий