jQuery add elements to empty selection?

后端 未结 9 1479
一向
一向 2020-12-29 18:52

Why doesn\'t this work?

var spans = $();
var elem = document.getElementById(\'someId\');
spans.add(elem);

What is the proper way to start

9条回答
  •  盖世英雄少女心
    2020-12-29 19:25

    If you're looking to push or add items selected from a jQuery object, you could also do this:

    var $els = $(),
        $someEls = $(".some-els");
    
    $els.push.apply($els, $someEls);
    

    Just another way to do it.

提交回复
热议问题