Shoutbox

Javascript Problem ...again (rewarding with joost or/and pownce invite) - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Javascript Problem ...again (rewarding with joost or/and pownce invite) (/showthread.php?tid=76945)

Javascript Problem ...again (rewarding with joost or/and pownce invite) by glennlopez on 08-22-2007 at 11:30 PM

Problem:
I can't seem to get the javascript to work on every div ID'ed with 'datesup' and 'datesub'. (it'll only work once on the first DIV with the ID datesup and datesub.

Question
How can I make my javascript work for any and ALL the DIV tag with the ID 'datesup' and 'datesub' ?

code:
<html ..etc...


<body>
NUMBER:
<div id="poop">18 August 2007</div>
<script language="javascript">
var element = document.getElementById("poop");
element.innerHTML = element.innerHTML.substr(0,2);
</script>
<p>
MONTH:
<div id="goop">18 August 2010</div>
<p>
<script language="javascript">
var element = document.getElementById("goop");
element.innerHTML = element.innerHTML.replace(/[*0-9]/g,'');
</script>
</p>




<div>
<div style="background-image:url(http://img292.imageshack.us/img292/2955/datesupbgrb5.gif); width:400px; height:30px; background-repeat:no-repeat; font-family:Arial, Helvetica, sans-serif; color:#FFFFFF; font-size:28px;"><div id="datesup" style=" margin-left:10px;">27 November 2007</div>
</div>

<div id="datesub" style="background-image:url(http://img215.imageshack.us/img215/993/datesubbgck1.gif); width:54px; height:14px; background-repeat:no-repeat; text-align:center; font-family:Arial, Helvetica, sans-serif; color:#FFFFFF; font-size:10px; margin-top:0px;">18 January 2007
</div>
</div>

<p>

<div>
<div style="background-image:url(http://img292.imageshack.us/img292/2955/datesupbgrb5.gif); width:400px; height:30px; background-repeat:no-repeat; font-family:Arial, Helvetica, sans-serif; color:#FFFFFF; font-size:28px;"><div id="datesup" style=" margin-left:10px;">27 November 2007</div>
</div>

<div id="datesub" style="background-image:url(http://img215.imageshack.us/img215/993/datesubbgck1.gif); width:54px; height:14px; background-repeat:no-repeat; text-align:center; font-family:Arial, Helvetica, sans-serif; color:#FFFFFF; font-size:10px; margin-top:0px;">18 January 2007
</div>
</div>

<script language="javascript">
var element = document.getElementById("datesup");
element.innerHTML = element.innerHTML.substr(0,2);
</script>
<script language="javascript">
var element = document.getElementById("datesub");
element.innerHTML = element.innerHTML.replace(/[*0-9]/g,'');
</script>

</body>



..../html>


RE: Javascript Problem ...again (rewarding with joost or/and pownce invite) by rav0 on 08-23-2007 at 07:57 AM

IDs are unique, you're not allowed to have more than one element sharing the same ID. You should use classes instead, the same class can be applied to as many elements as you like, and any element can have more than one class.


RE: Javascript Problem ...again (rewarding with joost or/and pownce invite) by Nathan on 08-23-2007 at 08:23 AM

Well as rav0 said, if you want to have multiple things use the same id, you willl have to use a class. A class will allow multiple divs to use it (when I said div, I mean anything in a tag :P)

<div class="poop"> jhgfds</div>

^^^^
Like that for example :)