Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4382430
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:46:42+00:00 2026-05-21T12:46:42+00:00

So I tried this: var allItems = jQuery(); function additems(items) { allItems = allItems.pushStack(items);

  • 0

So I tried this:

var allItems = jQuery();

function additems(items) {
    allItems = allItems.pushStack(items);
}

additems(jQuery("#ul1").find("li").first());
additems(jQuery("#ul2").find("li").first());
additems(jQuery("#ul3").find("li").first());


allItems.each(function() {
    jQuery("ul1").append(this);
});

She doesn’t work in jsFiddle.

What I need is to keep a collection of some <LI> items hopefully in a jQuery object. And i’d like it to use a function passing in a jQuery object. I also need to add to the collection inside a function like what I have above so it can be done at different times in the code.

i know i can get around it by something like:

function additems(items){
    items.each(function(){ allItems.pushStack(this);});
}

or by just sending them as a list of HTML <LI> Elements, but I’d rather do it something like the above and I haven’t found a clean and efficient way of doing this.

Thanks!

PS: I’d rather not need a plugin.

UPDATE

let me explain more. I have one function that does something and it has an <ul> element from which i can pull out the <li> elements.

I then want to send these elements to another function to keep them for later.

function doSomething1()
{
    //Do something

    var ulElement = getFromSomewhere();
    additems(jQuery(ulElement).find("li"));

    // do something else
    return;
}

function additems(items)
{
    MyObject.allItems.pushStack(items)
}

the jsFiddle was Simplified compared to my code.

new jsfiddle with “#” fixed http://jsfiddle.net/LPkkT/8/

ANSWER

Upon adding Quincy’s answer to my fiddle in a way that didn’t remove all my code i got:

var allItems = jQuery();

function additems(items) {
    allItems = allItems.add(items);
}

additems(jQuery("#ul1").find("li").first());
additems(jQuery("#ul2").find("li").first());
additems(jQuery("#ul3").find("li").first());


allItems.each(function() {
    jQuery("ol").append(this);
});

And this works.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T12:46:43+00:00Added an answer on May 21, 2026 at 12:46 pm

    Firstly, if you want to select by id, you have to add a '#' in the selector.
    And you can add jquery collections using the add() method

    var allItems = 
    
    
    jQuery("#ul1").find("li").first()
    .add(jQuery("#ul2").find("li").first())
    .add(jQuery("#ul3").find("li").first());
    
    
    allItems.each(function() {
        jQuery("ol").append($(this));
    });
    

    http://jsfiddle.net/LPkkT/4/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've honestly tried this left and right and still find that my mirror server,
I tried this XAML: <Slider Width=250 Height=25 Minimum=0 Maximum=1 MouseLeftButtonDown=slider_MouseLeftButtonDown MouseLeftButtonUp=slider_MouseLeftButtonUp /> And this
I tried this: ALTER TABLE My.Table DROP MyField and got this error: -MyField is
I tried this but it does not seem to be valid syntax. <xsl:element name=$myElementName></xsl:element>
I've tried this: string newScript = textBox1.Text; HtmlElement head = browserCtrl.Document.GetElementsByTagName(head)[0]; HtmlElement scriptEl =
I have tried this... Dim myMatches As String() = System.Text.RegularExpressions.Regex.Split(postRow.Item(Post), \b\#\b) But it is
Have you ever tried this before? static void Main(string[] args) { int x =
I've tried this both with and without the 'ExceptionType' parameter. I have an Error.aspx
(I've tried this in MySql) I believe they're semantically equivalent. Why not identify this
Has anyone already tried this, anything particulair that I need to be aware of?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.