473,395 Members | 1,422 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Help! Generating new <img> tags

# 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
2 1683
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
That'll work, thanks!

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ralph Freshour | last post by:
I have a PHP web app using MySQL - when I save a .jpg file named test's.jpg I see that the filename on the unix server is: test\'s.jpg - the filename I end up saving in my SQL table is named...
1
by: A | last post by:
Hi everyone I was working on a php script to display images and I am running into problems. My problems are when I execute the query to thumb path it won't display the image/s. Anyhelp is...
5
by: Lui Ali | last post by:
Hello, Problem: I want to get the whole text between the opening tag <%OPTIONAL%> and the closing tag <%/OPTIONAL%>. The right block is found by (and contains) the placeholder...
8
by: Hostile17 | last post by:
Consider the following HTML. ---------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> <html> <head> <meta...
2
by: Got2Go | last post by:
Hello, I am trying to come up with a function that will search the source of the page for a specific string. If that string is found, then have it modify specific tags inside of a table and...
4
by: Paul Hale | last post by:
Hi, This is my set up... Root (.aspx file for non-authenticated users) Root\Members (.aspx files for authenticated users) Root\Images (images for entire web site) My MasterPage resides in...
2
by: David Elliott | last post by:
I am creating a control to display GIF/JPEG images for my website. The control has a Panel to hold the images. I would like to perform the following. 1) store the original on disk and create a...
2
by: Sorbitol | last post by:
I'm trying to put two adjacent img tags inside a table cell example: <td><img class="imgclass" src=""/><img class="imgclass" src="" /></td> but i'm getting always a line break between images...
1
by: Dave | last post by:
Usual apologies if this is old territory. I'm resizing a bunch of iframes on a page to the height of their contained documents. Some of the contained documents contain IMG tags. On IE this...
7
by: ojsimon | last post by:
Hi I found this script on a forum and have been trying to make it work, but all it returns is a blank screen, i tried using the debug error reporting but got nothing from that either just a blank...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.