O.P. Javascript Problem ...again (rewarding with joost or/and pownce invite)
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>
<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>
This post was edited on 08-22-2007 at 11:31 PM by glennlopez.
Posts: 1419 Reputation: 29
35 / /
Joined: Aug 2003
RE: Javascript Problem ...again (rewarding with joost or/and pownce invite)
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.
| |
(\ /)
(O.o)
(> <)
This is Bunny. Copy Bunny into your signature to help him on his way to world domination
RE: Javascript Problem ...again (rewarding with joost or/and pownce invite)
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 )
<div class="poop"> jhgfds</div>
^^^^
Like that for example
Touch Innovation - touch friendly programs/applications for the windows mobile!