"$ (...) [0] .append is not a function" with jQuery

I am trying to add a line to a page. If I write $('.txt')in the console, it returns:

enter image description here

If I write $('.txt'), it returns the first .txt.

If I write $('.txt').append('<div><span>TEEST</span></div>')in the console, it adds "TEEST" to everyone .txton the page.

But if I write $('.txt')[0].append('<div><span>TEEST</span></div>') it returns:

enter image description here

Why is this? How can I add to a specific DOM element?

+4
source share
1 answer

[0] DOM, jQuery. append - jQuery , DOM (, , getElementById).

eq:

$('.txt').eq(0).append('<div><span>TEEST</span></div>');

:first:

$('.txt:first').append('<div><span>TEEST</span></div>');
+5

Source: https://habr.com/ru/post/1622248/


All Articles