468,101 Members | 1,316 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,101 developers. It's quick & easy.

ID names within a <div></div> pair?

Dear folks,

In Javascript, is it possible to get all id names within, say, a
<div></divpair? Like the array of "document.images", I mean.

The reason I ask, is that I have a calender whose <td></tdtable
elements, within a given <div></div>, all have a class type, one of which
is "today" (to highlight it). Once the calender is drawn, the Javascript
has ended. And since Javascript has no known (to me) method of storing
variables in say, the system environment, on re-use I'll have to resort to
canceling the classes for all ids within the calender before I can
highlight a different day.

Make sense? :)

Thanks,

- Mark
Feb 27 '07 #1
13 1931
On Feb 27, 4:03 pm, "Mark" <a...@asarian-host.netwrote:
Dear folks,

In Javascript, is it possible to get all id names within, say, a
<div></divpair? Like the array of "document.images", I mean.

The reason I ask, is that I have a calender whose <td></tdtable
elements, within a given <div></div>, all have a class type, one of which
is "today" (to highlight it). Once the calender is drawn, the Javascript
has ended. And since Javascript has no known (to me) method of storing
variables in say, the system environment, on re-use I'll have to resort to
canceling the classes for all ids within the calender before I can
highlight a different day.
You can make a persistent object that stores references to the cells
if you like. There are also various examples of
"getElementsByClassName" functions in the archives. You can also give
elements multiple classes, then add and remove them as required.

One technique is to give the table cells an ID based on the date that
they represent (remember to always prefix numbers with a letter to
ensure valid IDs), then you change the IDs as you change the dates -
anything is possible. There are hundreds of calendar scripts out
there already, Matt Kruse has one here:

<URL: http://www.javascripttoolbox.com/lib/calendar/ >

although it needs to be modified to fix the date format to something
more appropriate for the web (it uses the USA's peculiar mm/dd/yyyy
format) - I don't think it would be too difficult.
--
Rob

Feb 27 '07 #2
"RobG" <rg***@iinet.net.auwrote in message
news:11**********************@z35g2000cwz.googlegr oups.com...

Thank you very much. That was an extremely helpful answer! :)

- Mark
Feb 27 '07 #3
In comp.lang.javascript message <11**********************@z35g2000cwz.go
oglegroups.com>, Mon, 26 Feb 2007 22:50:44, RobG <rg***@iinet.net.au>
posted:
There are hundreds of calendar scripts out
there already, Matt Kruse has one here:

<URL: http://www.javascripttoolbox.com/lib/calendar/ >

although it needs to be modified to fix the date format to something
more appropriate for the web (it uses the USA's peculiar mm/dd/yyyy
format) - I don't think it would be too difficult.
It also starts the week with Sunday, even though the Almighty apparently
preferred Monday for that. But the "German" calendar just needs the
words to be translated from German to local preference. No mention of
the International Standard, of course. And I saw nothing on Week
Numbers.

while(this.getDay()%6==0) // is shorter than
while(this.getDay()==0 || this.getDay()==6)

IIRC, this.setHours(0, 0, 0, 0); worked in IE4.

In validating, there's no need to check for Leapness until it has been
established that it is a Feb 29 date. But for shorter code one can
compare the date with 28+Leap(Y) .

In <http://www.javascripttoolbox.com/lib/date/examples.php>, the "Adding
Time" demo must have a problem. If I add 7500000 seconds and 0..7 years
to 2000-01-01 01:00:00, I should not always get the same time of day.
And its input windows are too narrow, though 75e5 will fit.

Adding Years Months Days Result
7 2 23 March 24, 2007 1:00:00 AM (Saturday)
7 2 24 March 25, 2007 12:00:00 AM (Sunday)
7 2 25 March 26, 2007 1:00:00 AM (Monday)

One hour different, on one of the days.

Adding 7 2 23 23 59 00 -March 25, 2007 12:59:00 AM (Sunday)
Adding 7 2 23 23 59 60 -March 25, 2007 12:00:00 AM (Sunday)

so adding 60 seconds more makes it an hour earlier. The page would be
better if that used ISO format, or user's choice.

N.B. North Americans will (mostly) be able to do corresponding tests but
with a different date and time. Remember ISO 16262:2002 15.9.1.8, last
paragraph of p.120. (ECMA : first para).
BTW, ISO 8601:2004 is published on the Web in PDF (plain & zip).

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Feb 28 '07 #4
Dr J R Stockton wrote:
><URL: http://www.javascripttoolbox.com/lib/calendar/ >
It also starts the week with Sunday, even though the Almighty
apparently preferred Monday for that.
That's configurable.
No mention of the International Standard, of course.
Date format is also easily configurable.
And I saw nothing on Week Numbers.
Never implemented because I never had the need for it.
In validating, there's no need to check for Leapness until it has been
established that it is a Feb 29 date. But for shorter code one can
compare the date with 28+Leap(Y) .
Code was written years ago and never optimized. Although premature
optimization is unnecessary, the code could certainly stand to be less
verbose in places. A full re-write is on my to do list, and has been for
almost 2 years.
In <http://www.javascripttoolbox.com/lib/date/examples.php>, the
"Adding Time" demo must have a problem. If I add 7500000 seconds and
0..7 years to 2000-01-01 01:00:00, I should not always get the same
time of day.
Interesting. Have you looked at the code and found where the bug might be? I
have not yet verified myself that there is a bug, but if you have a patch it
would be great.
And its input windows are too narrow, though 75e5 will
fit.
I don't believe the maxlength prevents a larger value.
The page would be
better if that used ISO format, or user's choice.
I'm not sure by what standard "better" is judged.
Remember ISO 16262:2002
15.9.1.8, last paragraph of p.120. (ECMA : first para).
Hmm, I don't recall.
BTW, ISO 8601:2004 is published on the Web in PDF (plain & zip).
Well I'm sure that means somethin'

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Feb 28 '07 #5
Dr J R Stockton said the following on 2/27/2007 4:00 PM:
In comp.lang.javascript message <11**********************@z35g2000cwz.go
oglegroups.com>, Mon, 26 Feb 2007 22:50:44, RobG <rg***@iinet.net.au>
posted:
> There are hundreds of calendar scripts out
there already, Matt Kruse has one here:

<URL: http://www.javascripttoolbox.com/lib/calendar/ >

although it needs to be modified to fix the date format to something
more appropriate for the web (it uses the USA's peculiar mm/dd/yyyy
format) - I don't think it would be too difficult.

It also starts the week with Sunday, even though the Almighty apparently
preferred Monday for that.
Don't let half the world know that.

<snip>

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 28 '07 #6
On Feb 28, 3:47 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
Dr J R Stockton said the following on 2/27/2007 4:00 PM:
In comp.lang.javascript message <1172559044.090418.110...@z35g2000cwz.go
oglegroups.com>, Mon, 26 Feb 2007 22:50:44, RobG <r...@iinet.net.au>
posted:
There are hundreds of calendar scripts out
there already, Matt Kruse has one here:
<URL:http://www.javascripttoolbox.com/lib/calendar/>
although it needs to be modified to fix the date format to something
more appropriate for the web (it uses the USA's peculiar mm/dd/yyyy
format) - I don't think it would be too difficult.
It also starts the week with Sunday, even though the Almighty apparently
preferred Monday for that.

Don't let half the world know that.
Half? I think you've understated your case. ;-)

Christians make up only one third of the world's population, and some
of them (quite a few apparently) think the seventh day is Saturday.
Moslems, when using a Gregorian calendar, think its Friday.
--
Rob

Feb 28 '07 #7
RobG said the following on 2/28/2007 4:55 AM:
On Feb 28, 3:47 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
>Dr J R Stockton said the following on 2/27/2007 4:00 PM:
>>In comp.lang.javascript message <1172559044.090418.110...@z35g2000cwz.go
oglegroups.com>, Mon, 26 Feb 2007 22:50:44, RobG <r...@iinet.net.au>
posted:
There are hundreds of calendar scripts out
there already, Matt Kruse has one here:
<URL:http://www.javascripttoolbox.com/lib/calendar/>
although it needs to be modified to fix the date format to something
more appropriate for the web (it uses the USA's peculiar mm/dd/yyyy
format) - I don't think it would be too difficult.
It also starts the week with Sunday, even though the Almighty apparently
preferred Monday for that.
Don't let half the world know that.

Half? I think you've understated your case. ;-)
Probably so :)
Christians make up only one third of the world's population, and some
of them (quite a few apparently) think the seventh day is Saturday.
Moslems, when using a Gregorian calendar, think its Friday.
Judaism is also Friday.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 28 '07 #8
In comp.lang.javascript message <es*********@news1.newsguy.com>, Tue, 27
Feb 2007 18:58:46, Matt Kruse <ne********@mattkruse.composted:
>Dr J R Stockton wrote:
>No mention of the International Standard, of course.

Date format is also easily configurable.
But there is no mention of the International Standard, which includes a
useful explanation of why your locally-preferred formats are
unreasonable.
>And I saw nothing on Week Numbers.

Never implemented because I never had the need for it.
Well, ISTM that to do it right one needs to be thinking more clearly
than, for example, MS.
>In <http://www.javascripttoolbox.com/lib/date/examples.php>, the
"Adding Time" demo must have a problem. If I add 7500000 seconds and
0..7 years to 2000-01-01 01:00:00, I should not always get the same
time of day.

Interesting. Have you looked at the code and found where the bug might be? I
have not yet verified myself that there is a bug, but if you have a patch it
would be great.
No; it took me long enough to see where it rejected (correctly, of
course) Dec 32.
>And its input windows are too narrow, though 75e5 will
fit.

I don't believe the maxlength prevents a larger value.
The physical length prevents easy reading of a longer value, and there
is ample free space.
>The page would be
better if that used ISO format, or user's choice.

I'm not sure by what standard "better" is judged.
Well, about 95% of the world would prefer the time to use the 24-hour
clock; and it would be easier for everyone to check the date if that
also used numeric fields in descending order. Giving a choice is surely
better; one believes the USA to be in principle in favour of free
choice.
>Remember ISO 16262:2002
15.9.1.8, last paragraph of p.120. (ECMA : first para).

Hmm, I don't recall.
It is considerable importance to North Americans at the present time;
and particularly to those who publish such examples.
>BTW, ISO 8601:2004 is published on the Web in PDF (plain & zip).

Well I'm sure that means somethin'
You can find more, indirectly, by consulting the newsgroup FAQ.

I suggest that there should be an explicit and obvious statement of how
the code is intended to handle changes in offset from GMT.

There are basically three approaches :
(1) Consider every day to have 24 hours. For that, just use only the
UTC functions, which are quicker.
(2) Handle changes fully, which needs careful consideration of the exact
effects of the various non-UTC functions
(3) Neither of those.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Feb 28 '07 #9
In comp.lang.javascript message <v6********************@telcove.net>,
Wed, 28 Feb 2007 09:31:57, Randy Webb <Hi************@aol.composted:
>RobG said the following on 2/28/2007 4:55 AM:
>On Feb 28, 3:47 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
>>Dr J R Stockton said the following on 2/27/2007 4:00 PM:

In comp.lang.javascript message <1172559044.090418.110...@z35g2000cwz.go
oglegroups.com>, Mon, 26 Feb 2007 22:50:44, RobG <r...@iinet.net.au>
posted:
There are hundreds of calendar scripts out
there already, Matt Kruse has one here:
<URL:http://www.javascripttoolbox.com/lib/calendar/>
although it needs to be modified to fix the date format to something
more appropriate for the web (it uses the USA's peculiar mm/dd/yyyy
format) - I don't think it would be too difficult.
It also starts the week with Sunday, even though the Almighty apparently
preferred Monday for that.
Don't let half the world know that.
Half? I think you've understated your case. ;-)

Probably so :)
>Christians make up only one third of the world's population, and some
of them (quite a few apparently) think the seventh day is Saturday.
Moslems, when using a Gregorian calendar, think its Friday.

Judaism is also Friday.
Start/end of week and Holy Day (where applicable) are independent
concepts.

The Jewish Holy Day is not Friday, although it starts on Friday at
(sunset - 30 mins) or at 18:00 according to preference. They recognise
two types of week; starting or finishing on Saturday (which means Friday
evening to Saturday evening, in ISO 8601 terms).

Their Year 1 in fact started on a Monday, BC 3761-10-07 Julian.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "" (SonOfRFC1036)
Feb 28 '07 #10
In comp.lang.javascript message <es*********@news1.newsguy.com>, Tue, 27
Feb 2007 18:58:46, Matt Kruse <ne********@mattkruse.composted:
>In validating, there's no need to check for Leapness until it has been
established that it is a Feb 29 date. But for shorter code one can
compare the date with 28+Leap(Y) .

Code was written years ago and never optimized. Although premature
optimization is unnecessary, the code could certainly stand to be less
verbose in places. A full re-write is on my to do list, and has been for
almost 2 years.
That means that it will not be done.

Here's a start :
if (!Date.prototype.getFullYear) {
Date.prototype.getFullYear = function() { var yy=this.getYear();
return (yy<1900?yy+1900:yy); }

I've heard of a browser, I think, for which getYear() would currently
return 7. My site has a function getFY which is not much longer and
uses in effect only getYear()%100.

function getFY(D) { var YE // needs full test in all browsers
YE = 1970 + Math.round(D.getTime() / 31556952000) // s per Greg yr
return YE + (D.getYear()-YE)%100 }

Note : it is not sensitive to errors on the values of 1970 and
31556952000, since YE only determines the century.

this.isInteger = function(val) {
for (var i=0; i < val.length; i++) {
if ("1234567890".indexOf(val.charAt(i))==-1) {
return false;
}
}
return true;
};

can probably be

this.isInteger = function(val) ( return ! /\D/.test(val) }

if (interval=='y') { // year
this.setFullYear(this.getFullYear()+number);
}
else if (interval=='M') { // Month
this.setMonth(this.getMonth()+number);
}

Needs consideration of values that would land on a day that the
destination month does not have. Generally, use the last day of the
month; sometimes, the first of the next month. Wikipedia refers to a
case where a date/time in Feb 29 rounds down before noon and up from
noon.

Stepping weekdays can be optimised for speed by extracting multiples of
5 days and adding 7 days for each. If that is done with an appropriate
version of mod & div, the fractional-week count need only be forwards,
which may be simpler.
>In <http://www.javascripttoolbox.com/lib/date/examples.php>, the
"Adding Time" demo must have a problem. If I add 7500000 seconds and
0..7 years to 2000-01-01 01:00:00, I should not always get the same
time of day.

Interesting. Have you looked at the code and found where the bug might be? I
have not yet verified myself that there is a bug, but if you have a patch it
would be great.
Apart from your determination of the current year, probably everything
else can be done in Greenwich Time. It is especially obvious, as 3/11
approaches, what problem that annihilates. The UTC methods should be
several times faster; and in at least one case (same date) are not
needed at least for post-1969. (check that)

Math.floor(D1/864e5) == Math.floor(D2/864e5)

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Mar 3 '07 #11
Dr J R Stockton wrote:
>A full re-write is on my to do list, and has
been for almost 2 years.
That means that it will not be done.
What else can you tell me about my future, all-seeing one?!

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Mar 3 '07 #12
In comp.lang.javascript message <es*********@news5.newsguy.com>, Fri, 2
Mar 2007 22:22:43, Matt Kruse <ne********@mattkruse.composted:
>Dr J R Stockton wrote:
>>A full re-write is on my to do list, and has
been for almost 2 years.
That means that it will not be done.

What else can you tell me about my future, all-seeing one?!
Well, it would be non-constructive to say that you'll be so determined
to prove me wrong that you'll fully rewrite it within the next week, so
I won't.

For conversion from 24-hr H to 12-hr h, consider h = 1 + (H+11)%12
as per IIRC via the FAQ.

ISTM that isBlank should recognise \u00A0 and maybe others.

Does parseFloat really use a second parameter? parseFloat(val) >= 0
should do except for the case of "-0" (see its comment); but I don't see
that yours tests for positive.

The knowledge base search seems good at first on "Date Validation" and
"Lagrange Point", but I learned little from its results :-( .

A further prediction is that if you go for a policy of incremental
improvement, utility and uptake will increase more rapidly than
otherwise. In particular, the absence of RegExps in parts of the code
makes it look very dated. They're in small Flanagan of Oct 1998.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- FAQqish topics, acronyms & links;
Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Mar 3 '07 #13
Dr J R Stockton wrote:
>What else can you tell me about my future, all-seeing one?!
Well, it would be non-constructive to say that you'll be so determined
to prove me wrong that you'll fully rewrite it within the next week,
so I won't.
Rest assured, your sphere influence is far greater in your mind than in
reality ;)

I'm currently working on completing my table-handling script, which handles
sorting, filtering, paging, and aggregating. It's quite a challenging and
interesting script to work on, with considerable practical applications to
my current work. The calendar popup, not so much.
A further prediction is that if you go for a policy of incremental
improvement, utility and uptake will increase more rapidly than
otherwise. In particular, the absence of RegExps in parts of the code
makes it look very dated. They're in small Flanagan of Oct 1998.
I wrote that code back when I needed to support a browser without regular
expressions, and when I converted it to its new form I wasn't interested in
re-writing working logic. Now, such browsers are probably non-existent in
the real world, and the code I write now makes use of regular expressions
whenever necessary.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Mar 4 '07 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Daniel Hansen | last post: by
3 posts views Thread by Josef K. | last post: by
2 posts views Thread by Nikolai Onken | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.