0
0m4r
Hello,
I'm quite new with Javascript and so actually I'm trying to learn
something about it.
I want to "extend" the Image DOM element, so I wrote this Javascript
code:
=== MyImg.js ===
function MyImg(imgsrc){
this.src = imgsrc;
}
MyImg.prototype = new Image();
=== /MyImg.js ===
Then I put this code int an HTML page:
=== index.html ==
[...some HTML header stuff...]
<script language=..... >
function load(){
var container = document.getElementById("test1");
var container1 = document.getElementById("test2");
var gImg = new MyImg("Image1.jpg");
var gImg1 = new MyImg("Image2.jpg");
container.appendChild(gImg);
container.appendChild(gImg1);
container1.innerHTML = gImg.src + "<br>" + gImg1.src;
</script>
</head>
<body onload="load">
<div id="test1"/>
<div id="test2"/>
</body>
</html>
=== /index.html ===
and here is the result I have back:
=== generated HTML code ===
<div id="test1">
<img src="Image2.jpg"/>
</div>
<div id="test2">
Image2.jpg<br/>Image2.jpg
</div>
=== /generated HTML code ===
Instead of what I expect:
=== expected HTML code ===
<div id="test1">
<img src="Image1.jpg"/>
<img src="Image2.jpg"/>
</div>
<div id="test2">
Image1.jpg<br/>Image2.jpg
</div>
=== /expected HTML code ===
Where I'm wrong? Could anybody help me?
Thanks a lot,
Omar
I'm quite new with Javascript and so actually I'm trying to learn
something about it.
I want to "extend" the Image DOM element, so I wrote this Javascript
code:
=== MyImg.js ===
function MyImg(imgsrc){
this.src = imgsrc;
}
MyImg.prototype = new Image();
=== /MyImg.js ===
Then I put this code int an HTML page:
=== index.html ==
[...some HTML header stuff...]
<script language=..... >
function load(){
var container = document.getElementById("test1");
var container1 = document.getElementById("test2");
var gImg = new MyImg("Image1.jpg");
var gImg1 = new MyImg("Image2.jpg");
container.appendChild(gImg);
container.appendChild(gImg1);
container1.innerHTML = gImg.src + "<br>" + gImg1.src;
</script>
</head>
<body onload="load">
<div id="test1"/>
<div id="test2"/>
</body>
</html>
=== /index.html ===
and here is the result I have back:
=== generated HTML code ===
<div id="test1">
<img src="Image2.jpg"/>
</div>
<div id="test2">
Image2.jpg<br/>Image2.jpg
</div>
=== /generated HTML code ===
Instead of what I expect:
=== expected HTML code ===
<div id="test1">
<img src="Image1.jpg"/>
<img src="Image2.jpg"/>
</div>
<div id="test2">
Image1.jpg<br/>Image2.jpg
</div>
=== /expected HTML code ===
Where I'm wrong? Could anybody help me?
Thanks a lot,
Omar