html
html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<img
src="https://cdn.pixabay.com/photo/2021/04/14/11/04/japanese-white-eye-6178082_1280.jpg"
width="320"
height="215"
/>
<button onclick="myFunction()">Click Here</button>
</body>
</html>
Enter to Rename, Shift+Enter to Preview
css
css
1
2
3
4
body
{
}
Enter to Rename, Shift+Enter to Preview
js
js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function myFunction() {
var x = document.getElementsByTagName("IMG")[0];
// x.getAttributeNode("src").value =
// "https://cdn.pixabay.com/photo/2021/04/13/09/46/river-6175173_1280.jpg";
/* this line works */
x.getAttribute("src") =
"https://cdn.pixabay.com/photo/2021/04/13/09/46/river-6175173_1280.jpg";
}
/*this line doesn't work. it doesn't work with getAttribute! */
/*question:
although getAttributeNode().value and getAttribute() are the same thing,
in this case one works and the other doesn't!
I tried getAttribute() instead of getAttributeNode().value on other cases
and it worked. but in this one(with img's src) it doesn't.
why is that? I'm confused.
*/
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run