By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,628 Members | 1,696 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,628 IT Pros & Developers. It's quick & easy.

Help! Generating new <img> tags

P: n/a
# SIMPLE VERSION #
Is there a way I can create a new <img> tag onClick?
# DETAILED VERSON #
I'm making a game that involves drawing a path between two points on a
grid. I've got the pathfinding routine working fine, but drawing it
out on a grid is proving difficult. Since I can't just draw a line
segment, I made a set of graphics to use: a bit of horizontal line,
vertical line, and two diagonals. I just take a few copies of each and
move them around to where they need to be. However, the number of
these graphics (and, thus, the number of <img> tags) I'm going to need
is impossible to predict. How can I add (and, for extra credit,
remove) <img> tags to the page without having to reload?
# PSEUDO-CODE VERSION #
function NewImg(url){
document.addHTML('<img src="' + url + '" alt="">');
}
..
..
..
<input type="button" value="Add" onClick="NewImg(url);">

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Th******@gmail.com wrote:
# SIMPLE VERSION #
Is there a way I can create a new <img> tag onClick?
# DETAILED VERSON #
I'm making a game that involves drawing a path between two points on a
grid. I've got the pathfinding routine working fine, but drawing it
out on a grid is proving difficult. Since I can't just draw a line
segment, I made a set of graphics to use: a bit of horizontal line,
vertical line, and two diagonals. I just take a few copies of each and
move them around to where they need to be. However, the number of
these graphics (and, thus, the number of <img> tags) I'm going to need
is impossible to predict. How can I add (and, for extra credit,
remove) <img> tags to the page without having to reload?
# PSEUDO-CODE VERSION #
function NewImg(url){
document.addHTML('<img src="' + url + '" alt="">');
}


function NewImage(u){
var oImg = document.createElement('img');
oImg.src = u;
oImg.alt = '';
document.getElementsByTagName('body')[0].appendChild(oImg);
}

[...]

--
Fred
Jul 23 '05 #2

P: n/a
That'll work, thanks!

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.