Jump to content

Capture index of calling tag


mtorbin

Recommended Posts

Hey all,

 

I'm trying to write a script that will capture the index number of the calling tag (be it an anchor tag, a div, or whatever).  As an experiment, I set up the following:

<html>
<head>
	<title></title>
	<script type="text/javascript">
		function showDivNmbr(myElement) {
			alert(myElement);
		}
	</script>
	<style type="text/css">
	#divContainer{width:270px;border:1px #000 solid;overflow:auto;}
	.singleDiv{text-align:center;width:50px;margin:2px;background-color:#777;float:left;}
	.singleDiv a{color:#fff;text-decoration:none;}
	</style>
</head>
<body>
	<div id="divContainer">
		<div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div1">one</a></div>
		<div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div2">two</a></div>
		<div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div3">three</a></div>
		<div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div4">four</a></div>
		<div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div5">five</a></div>
		<div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div6">six</a></div>
		<div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div7">seven</a></div>
		<div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div8">eight</a></div>
		<div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div9">nine</a></div>
		<div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div10">ten</a></div>
	</div>
</body>
</html>

 

Any suggestions would be most helpful.

 

Thanks,

 

- MT

Link to comment
Share on other sites

I got a little closer but now I want to be able to get this data without having to pass it:

<html>
<head>
	<title></title>
	<script type="text/javascript">
		function showDivNmbr() {
			alert(myElement);
		}
	</script>
	<style type="text/css">
	#divContainer{width:270px;border:1px #000 solid;overflow:auto;}
	.singleDiv{text-align:center;width:50px;margin:2px;background-color:#777;color:#fff;cursor:pointer;float:left;}
	</style>
</head>
<body>
	<div id="divContainer">
		<div class="singleDiv" onClick="showDivNmbr()" id="div1">one</div>
		<div class="singleDiv" onClick="showDivNmbr()" id="div2">two</div>
		<div class="singleDiv" onClick="showDivNmbr()" id="div3">three</div>
		<div class="singleDiv" onClick="showDivNmbr()" id="div4">four</div>
		<div class="singleDiv" onClick="showDivNmbr()" id="div5">five</div>
		<div class="singleDiv" onClick="showDivNmbr()" id="div6">six</div>
		<div class="singleDiv" onClick="showDivNmbr()" id="div7">seven</div>
		<div class="singleDiv" onClick="showDivNmbr()" id="div8">eight</div>
		<div class="singleDiv" onClick="showDivNmbr()" id="div9">nine</div>
		<div class="singleDiv" onClick="showDivNmbr()" id="div10">ten</div>
	</div>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.