loading...

re: Beyond appendChild: Better convenience methods for HTML VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Hi Sam, For some reasons I stumbled upon your article while googling and if I may ask, how would you write vanilla JS for this $(".accordion...
 

For a one-liner... hmm:

document.querySelector('.accordion-title').prepend(
  Object.assign(document.createElement('span'), {className: 'toggle', innerHTML: '<span></span><span></span>'}),
);

If you're not happy using innerHTML then it could look like this:

const toggleEl = Object.assign(document.createElement('span'), {class: 'toggle'});
toggleEl.append(document.createElement('span'), document.createElement('span'));
document.querySelector('.accordion-title').prepend(toggleEl);
code of conduct - report abuse