S
S
sergemin2017-02-19 20:41:11
JavaScript
sergemin, 2017-02-19 20:41:11

Uncaught TypeError: $target.find is not a function Why don't methods work?

Friends, I have been working with jQuery for about two weeks and this question arose. There is a list of elements. If I access any element directly, then I can apply all methods to it, but if I hang a handler on the entire list (so-called event delegation) or use the each() method, then I get this error
Uncaught TypeError: $ target.find is not a function Here is the html

code itself

<ul id='myList'>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
</ul>


jQuery
$('#myList').bind('click', function(event) {
        var $target = event.target;
        if($target.tagName !== 'LI') return;
        
        var $currentPersonMenu = $target.find('.personMenu'); // тут ошибка! Не работает метод
        console.log($currentPersonMenu);
    })


i.e. I can't access the child elements, nor can I use other methods like find(), closest(), ect.

I noticed that if I access the element directly, then if I output it to the console, I get the element in the form of an object, and if through delegation, then just in the form of a tag, the console displays it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rikcon, 2017-02-19
@sergemin

var $target = $(event.target);
Here, in event.target is not a jquery object, but a regular javascript object.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question