Answer the question
In order to leave comments, you need to log in
Why doesn't replaceWith work?
When executing the code below, it throws an error "Uncaught TypeError: box[i].replaceWith is not a function". Why?
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div class="box">1</div>
<div class="box">2</div>
<script>
var a = document.createElement('a');
a.href = '#';
a.innerHTML = 'links';
var box = document.getElementsByClassName('box');
for(var i = 0, count = box.length; i < count; i++) {
box[i].replaceWith(a);
}
</script>
</body>
</html>
<div class="box">1</div>
, etc. to the link?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question