Skip to content
This repository has been archived by the owner on Feb 24, 2022. It is now read-only.

How to add element to an existing DOMtastic instance ? #58

Closed
Wikiki opened this issue May 19, 2017 · 2 comments
Closed

How to add element to an existing DOMtastic instance ? #58

Wikiki opened this issue May 19, 2017 · 2 comments

Comments

@Wikiki
Copy link
Contributor

Wikiki commented May 19, 2017

Hi,

how can we add a new DOMtastic instance to an existing one like .add() function do in jQuery ?

regards,

@Wikiki Wikiki changed the title How to add element to DOMtastic instance ? How to add element to an existing DOMtastic instance ? May 19, 2017
@Wikiki
Copy link
Contributor Author

Wikiki commented May 20, 2017

Hi again,

I wrote this code:

export const add = function( elements ) {
  const nodes = this.nodeType ? [ this ] : this;
  if ( typeof elements === 'string' ) {
    elements = querySelector( elements );
  } else {
    elements = Array.isArray( elements ) ? elements : [ elements ];
  }
  each( elements, element => {
    if ( nodes.indexOf( element ) === -1 ) {
      nodes.push( element );
    }
  } );
  return hexadogJS( nodes );
};

what do you think about it ?

regards,

@webpro
Copy link
Owner

webpro commented May 22, 2017

Discussion is in #61.

@webpro webpro closed this as completed May 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants