Answer the question
In order to leave comments, you need to log in
How to insert a div from one html into another, while editing the elements in it?
I have two html files, one is the main code, the other contains svg blocks that should be changed using js.
var xhr= new XMLHttpRequest();
xhr.open('GET', 'kakoyito-html.html', true);
xhr.onreadystatechange= function() {
if (this.readyState!==4) return;
if (this.status!==200) return; // or whatever error handling you want
document.getElementById('config_block').innerHTML= this.responseText;
};
xhr.send();
const option_price = document.querySelector('.option_price');
const priceArg = document.querySelectorAll('[price]');
const optionSum = () => {
oprion_sum = 0;
for (let i = 0; i < priceArg.length; i++) {
if (priceArg[i].checked) {
oprion_sum += +priceArg[i].getAttribute('price');
}
}
if (oprion_sum > 0) {
let arr = [];
let srt = oprion_sum.toString().split('');
for (let [i, count] = [srt.length - 1, 1]; i >= 0; i--) {
count++;
if (count === 5) {
arr.unshift(' ');
}
arr.unshift(srt[i]);
}
option_price.childNodes[0].data = arr.join('');
} else {
option_price.childNodes[0].data = oprion_sum;
}
return oprion_sum;
};
Answer the question
In order to leave comments, you need to log in
Use fetch it is easy to use and if the html is on the same domain then CORS will not bother
After receiving the response, display it anywhere and outside of fetch already change it
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question