Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery add function doesn't work as expected

The following snippet doesn't work.

var empty = $();
var divs = $("div");
empty.add(divs);

There is a div element in the HTML and it is added correctly to divs. But the divs collection is not added to the empty jquery object. Any ideas what`s wrong with that?

like image 434
Dirk Avatar asked Aug 14 '12 07:08

Dirk


1 Answers

.add won't change the original object. Try:

empty = empty.add(divs);
like image 105
xdazz Avatar answered Sep 27 '22 19:09

xdazz