I have a page slider, each slide has a separate article. For each article its own block with sharing. Is it possible to hang up creating a new block by passing the class name instead of id argument? Because otherwise, you will have to create a new id each time and access it. Now when accessing through the class name I get an error:

 this.initSocshare = function(el, services) { new Ya.share2(el, { content: { url: 'https://yandex.com', title: 'Yandex', theme: { services: services } } }); } 

And acc. I call:

 initSocshare('.socshare_b-container', 'facebook,twitter,vkontakte,gplus'); 

Here is the mistake:

 Uncaught DOMException: Failed to execute 'querySelectorAll' on 'Document': '#.socshare_b-container' is not a valid selector. 

I tried to call and with a point and without.

    1 answer 1

    No, you cannot specify a class selector in the constructor.

    But, as stated in the documentation , you can pass the element itself.

     const el = document.querySelector('.my-class'); Ya.share2(el, params); 

    Note that new does not need to be used when creating a block.