mtorbin Posted August 18, 2009 Share Posted August 18, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/170831-capture-index-of-calling-tag/ Share on other sites More sharing options...
mtorbin Posted August 18, 2009 Author Share Posted August 18, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/170831-capture-index-of-calling-tag/#findComment-900934 Share on other sites More sharing options...
KevinM1 Posted August 18, 2009 Share Posted August 18, 2009 What do you mean by 'index number'? Quote Link to comment https://forums.phpfreaks.com/topic/170831-capture-index-of-calling-tag/#findComment-900947 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.