Here is the code:
var img = document.createElement('img');
//debugger;
console.log(img);
[1, 2].forEach(function (item) {
console.log(img);
img.removeAttribute("src")
console.log(img);
var img_src = document.createAttribute("src");
img_src.value = '/test?id=' + item;
img.setAttributeNode(img_src);
console.log(img);
});
At first I ran it on Chrome and get the result:
<img src="/test?id=2">
<img src="/test?id=2">
<img src="/test?id=2">
<img src="/test?id=2">
<img src="/test?id=2">
<img src="/test?id=2">
<img src="/test?id=2">
But when I use step into in debugger or run it on Firefox,the result is the same as I thought:
<img>
<img>
<img>
<img src="/test?id=1">
<img src="/test?id=1">
<img>
<img src="/test?id=2">
Maybe the better way is to put the statement in the forEach function.
Is this a bug in developer tool of Chrome?