Меню Закрыть

Find is not a function

Содержание

Друзья, около двух недель работаю с jQuery и такой вопрос возник. Есть список элементов. Если я обращаюсь напрямую к какому-либо элементу, то я могу применять к нему все методы, но если я вешаю обработчик на весь список (так называемое делегирование событий) или использую метод each(), то я получаю эту ошибку
Ошибка Uncaught TypeError: $target.find is not a function

то есть я не могу обратиться ни к дочерним элементам, ни использовать другие методы, такие, как find(), closest(), ect.

Заметил, что если обращаюсь к элементу напрямую, то если его вывести в консоль, получаю элемент в виде объекта, а если через делегирование, то просто в виде тега выдает консоль его

Comments

Copy link Quote reply

MartaLoBalastegui commented Apr 8, 2019

I’m trying to assign a function when the close button of my pop-up is clicked:

But the alert is never displayed as an error is produced, the message in the console:
"b.find is not a function"

This comment has been minimized.

Copy link Quote reply

hbcondo commented Apr 11, 2019

I’m experiencing the same issue. When the close icon is clicked, the popup will disappear but the modal stays and throws this error. If I click outside the popup, both the popup and the modal disappears successfully. Why would clicking outside work but clicking the x icon doesn’t?

This comment has been minimized.

Copy link Quote reply

dannio commented Oct 14, 2019

I’m actually experiencing the exact same thing right now. Strange as it seems only applicable when closing the modal via clicking the button rather than the mask layer.

Читайте также:  Полное удаление sql server 2008

I have written a small JS to iterate through a set of matched elements and perform some task on each of them.

Here is the code:

When I console log element it outputs properly and the exact objects. Why should jquery throw this error?

4 Answers 4

because element is a dom element not a jQuery object

Inside the each() handler you will get the dom element reference as the second parameter, not a jQuery object reference. So if you want to access any jQuery methods on the element then you need to get the elements jQuery wrapper object.

Рекомендуем к прочтению

Добавить комментарий

Ваш адрес email не будет опубликован.