/    Sign up×
Community /Pin to ProfileBookmark

Is there a simpler way to do this?

Is there a simpler way to do this?

[code=html]<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN”
“http://www.w3.org/TR/html4/strict.dtd”>

<html lang=”en”>
<head>

<meta http-equiv=”content-type” content=”text/html; charset=iso-8859-1″>

<script type=”text/javascript”>
function position(caller)
{
IMGs = caller.parentNode.getElementsByTagName(‘img’)
for(i=0;i<IMGs.length;i++)
if(IMGs[i] === caller)
{
alert(‘the image position is: ‘ + i)
}
}
</script>

<title>test</title>

</head>

<body>

<div id=”myImages”>

<img src=”myimage.jpg” onclick=”position(this)” width=”50″ height=”50″ alt=”image”>
<img src=”myimage.jpg” onclick=”position(this)” width=”50″ height=”50″ alt=”image”>
<img src=”myimage.jpg” onclick=”position(this)” width=”50″ height=”50″ alt=”image”>
<img src=”myimage.jpg” onclick=”position(this)” width=”50″ height=”50″ alt=”image”>
<img src=”myimage.jpg” onclick=”position(this)” width=”50″ height=”50″ alt=”image”>

</div>

</body>

</html>[/code]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterMay 05.2006 — One way:
<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"&gt;

&lt;html lang="en"&gt;
&lt;head&gt;

&lt;meta http-equiv="content-type" content="text/html; charset=iso-8859-1"&gt;

&lt;script type="text/javascript"&gt;
function position(t)
{
alert('the image's TD position is: '+t.parentNode.cellIndex+"nTR position is:"+t.parentNode.parentNode.rowIndex)
}
&lt;/script&gt;

&lt;title&gt;test&lt;/title&gt;

&lt;/head&gt;

&lt;body&gt;

&lt;div id="myImages"&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;&lt;img src="myimage.jpg" onclick="position(this)" width="50" height="50" alt="image"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="myimage.jpg" onclick="position(this)" width="50" height="50" alt="image"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="myimage.jpg" onclick="position(this)" width="50" height="50" alt="image"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="myimage.jpg" onclick="position(this)" width="50" height="50" alt="image"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="myimage.jpg" onclick="position(this)" width="50" height="50" alt="image"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;img src="myimage.jpg" onclick="position(this)" width="50" height="50" alt="image"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="myimage.jpg" onclick="position(this)" width="50" height="50" alt="image"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="myimage.jpg" onclick="position(this)" width="50" height="50" alt="image"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="myimage.jpg" onclick="position(this)" width="50" height="50" alt="image"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="myimage.jpg" onclick="position(this)" width="50" height="50" alt="image"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;

&lt;/body&gt;

&lt;/html&gt;
Copy linkTweet thisAlerts:
@bokehauthorMay 05.2006 — Is there not some method I can use to query the image object or parent node directly?
×

Success!

Help @bokeh 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.28,
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,
)...