Answer the question
In order to leave comments, you need to log in
How to create a neighbor (tag)?
I have a lot of links on the page like <a href="some" class="tab-category">some</a>
How can I create another link next to each link like <a><img></a>
?
Answer the question
In order to leave comments, you need to log in
document.querySelectorAll('.tab-category').forEach(
link => link.insertAdjacentHTML('afterend', '<a><img></a>')
)
Either on css as written above, or on js, for example api.jquery.com/insertafter
Roughly something like this
var anchors = document.querySelectorAll('a.tab-category');
for(var i = 0; i < anchors.length; i++) {
var a = document.createElement("a");
a.appendChild(document.createElement("a"));
anchors[i].parentNode.insertBefore(a, a.nextElementSibling);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question