What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Javascript Problem ...again (rewarding with joost or/and pownce invite)

Javascript Problem ...again (rewarding with joost or/and pownce invite)
Author: Message:
glennlopez
New Member
*


Posts: 6
Joined: Jun 2005
O.P. Cool  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>




<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>


This post was edited on 08-22-2007 at 11:31 PM by glennlopez.
08-22-2007 11:30 PM
Profile E-Mail PM Find Quote Report
rav0
Veteran Member
*****

Avatar
i have an avatar

Posts: 1419
Reputation: 29
35 / Male / Flag
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.
| [Image: dorsh] |

(\ /)
(O.o)
(> <)

This is Bunny. Copy Bunny into your signature to help him on his way to world domination
08-23-2007 07:57 AM
Profile E-Mail PM Web Find Quote Report
Nathan
Veteran Member
*****

Avatar
Yeah, "large dimensions" ;)

Posts: 2984
Reputation: 76
– / Male / Flag
Joined: Apr 2005
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 :P)

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

^^^^
Like that for example :)
Touch Innovation - touch friendly programs/applications for the windows mobile!


08-23-2007 08:23 AM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On