A
A
Andrey Frolov2015-10-31 19:36:32
JavaScript
Andrey Frolov, 2015-10-31 19:36:32

Question about javascript and outerHTML. Why is that?

Why in this example (i++) elements are replaced through one
plnkr.co/edit/5SDvtVa3pWmN7XgHjRL8?p=preview
and in this (i+1) everything is fine?
plnkr.co/edit/4WwtyObE8gXrMAg7jQpT?p=preview

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Inchin ☢, 2015-10-31
@farpram

I think I already explained to you here: Why doesn't replaceWith work?

var links = document.getElementsByClassName('link-span');
    
while(links.length) {
    links[0].outerHTML = '<a target="_blank" href="#">New элемент</a>';
}

In your current example, i+1it does absolutely nothing with the variable - ias it was 0, it will remain 0.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question