How to combine insert loop in constructor?

  • 0
    Hello. I made my own mini-plugin for customizing select, but I came across the fact that when there are several identical selectors on the page, js does not work. It is understandable why, because you need a loop with iteration. If I put the index manually, which I did on the first line in the constructor, everything worked, but of course it doesn't work.

    What can be done to make it possible to add several elements to the page and they all work correctly?

    JavaScript Anonymous, Feb 27, 2019

  • 1 Answers
  • 0
    constructor(el) {
    if (typeof el === 'string') {
    el = document.querySelectorAll(el);
    }

    if (typeof el[Symbol.iterator] === 'function') {
    return [...el].map(n => new Select(n));
    }

    this.$select = el;

    // дальше всё по-старому
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!