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-title").prepend( '<span class="toggle"><span></span><span></span></span>' );
Your input is much appreciated ;)
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);
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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
Your input is much appreciated ;)
For a one-liner... hmm:
If you're not happy using innerHTML then it could look like this: