/    Sign up×
Community /Pin to ProfileBookmark

duplicate elements

Im trying to duplicate an image multiple times here is what I have

[CODE]
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml”>

<head>
<title></title>

<script type=”text/javascript”>
var totalNumber = 1000;
function insert(num) {
var cont = document.getElementById(“cont”);
var img = document.createElement(“img”);
var percent = num/totalNumber;
var result = cont.offsetWidth * percent;
var dup = result/100*2;
img.src = “guy.jpg”;
cont.appendChild(img);
}
</script>

<style type=”text/css”>
#cont {height:100px; width:500px;}
</style>

</head>
<body>

<div id=”cont”></div>

</body>

<script type=”text/javascript”>
insert(3000);
</script>

</html>

[/CODE]

So Im trying to get img to repeat the variable “dup”
so you would see <img src=”guy.jpg”> 30 times.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERFeb 03.2011 — What is the variable 'dup' supposed to do? You only set it and never use it?

Also, why so complicated with the math using 3000 and 1000, etc?

What is this trying to accomplish?

?
Copy linkTweet thisAlerts:
@mrhooFeb 03.2011 — [CODE]<!DOCTYPE html>
<head>
<title>duplicates</title>
<style> #cont{height: 100px; width: 500px;}</style>
<script>
function insert(num){
var cont= document.getElementById('cont'),
img= document.createElement('img');
img.src= 'guy.jpg';
cont.appendChild(img);
while(--num){
cont.appendChild(img.cloneNode());
}
return cont;
}
</script>
</head>
<body>
<div id= "cont"></div>
<script> insert(30)</script>
</body>
</html> [/CODE]
×

Success!

Help @mikewgd spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...