Javascript.RU

Создать новую тему Ответ
 
Опции темы Искать в теме
  #1 (permalink)  
Старый 07.04.2023, 12:23
Новичок на форуме
Отправить личное сообщение для iosman Посмотреть профиль Найти все сообщения от iosman
 
Регистрация: 21.05.2020
Сообщений: 3

jquery not working after ajax-jv page refresh ?
Hello,

I myself am new to this business, so the question is about the following situation:

- there is a script on the page that decorates the page:
1
$('.firm_card_container').hover(function(){
2
$(this).children().not('.r_gl_3').css('background-color','#FFE9CC');
3
}, function(){
4
$(this).children().not('.r_gl_3').css('background-color','#EFF9F8');
5
})


when the page loads - the script runs on the content. when content is updated by ajax script - above mentioned script is not working. the site is written on a framework and it is impossible to add code to the framework by adding code to update the above script. Someone tell you what to do.


thanks
jackyjoy
Ответить с цитированием
  #2 (permalink)  
Старый 07.04.2023, 14:32
Профессор
Отправить личное сообщение для Nexus Посмотреть профиль Найти все сообщения от Nexus
 
Регистрация: 04.12.2012
Сообщений: 3,733

Your script stops working after content updating 'cause «updating» replaces old content with your listeners with new one without them.
You can solve that problem by delegating the listeners to the closest parent which won't be changed by ajax or you can just listen document events.

Example of code:
$(function () {
    $(document).on('mouseenter', '.firm_card_container > :not(.r_gl_3)', function () {
        $(this).css('background-color', '#FFE9CC');
    }).on('mouseleave', '.firm_card_container > :not(.r_gl_3)', function () {
        $(this).css('background-color', '#EFF9F8');
    });
});
Ответить с цитированием
Ответ



Опции темы Искать в теме
Искать в теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Просмотрела исходик jQuery Откорректируйте где не верно taksebe jQuery 5 23.11.2018 22:42
Как из Google Расширения отправить AJAX? $ undefined jquery sciper AJAX и COMET 2 03.08.2018 07:57
Книги по Ajax BaVa Учебные материалы 18 18.08.2013 14:05
Получить функцию JavaScript (PHP, AJAX, jQuery) Sinot jQuery 3 04.02.2013 13:32
jQuery ajax дублирует запрос lexx006 jQuery 7 21.12.2012 11:23