By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,712 Members | 2,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,712 IT Pros & Developers. It's quick & easy.

How would I use JS to get this value?

P: n/a
Hi,

On my HTML page, I have a number of SPANs like

<span class="myNumber">3</span>

What I would like is a way to return the maximum number in between the
SPANs. You can assume that if I have an HTML block like the above, I
will also have

<span class="prescriptionNumber">1</span>
<span class="prescriptionNumber">2</span>

somewhere on my page before it.

Thanks for your help, - Dave
Aug 3 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
laredotornado wrote on 03 aug 2008 in comp.lang.javascript:
Hi,

On my HTML page, I have a number of SPANs like

<span class="myNumber">3</span>

What I would like is a way to return the maximum number in between the
SPANs. You can assume that if I have an HTML block like the above, I
will also have

<span class="prescriptionNumber">1</span>
<span class="prescriptionNumber">2</span>

"returning the maximum number in between the SPANs."

What is a "maximum number in between"?
somewhere on my page before it.
Before what it?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 3 '08 #2

P: n/a
laredotornado meinte:
Hi,

On my HTML page, I have a number of SPANs like

<span class="myNumber">3</span>

What I would like is a way to return the maximum number in between the
SPANs. You can assume that if I have an HTML block like the above, I
will also have

<span class="prescriptionNumber">1</span>
<span class="prescriptionNumber">2</span>

somewhere on my page before it.
(1) Get collection of all spans with className "prescription".
(2) Collect the first childNode of all those spans.
(3) convert the nodeValues of those childNodes to numbers (if needed).
(4) search highest value of those numbers.

Gregor


--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Aug 3 '08 #3

P: n/a
On Aug 3, 3:15*pm, Gregor Kofler <use...@gregorkofler.atwrote:
laredotornadomeinte:
Hi,
On my HTML page, I have a number of SPANs like
<span class="myNumber">3</span>
What I would like is a way to return the maximum number in between the
SPANs. *You can assume that if I have an HTML block like the above, I
will also have
<span class="prescriptionNumber">1</span>
<span class="prescriptionNumber">2</span>
somewhere on my page before it.

(1) Get collection of all spans with className "prescription".
(2) Collect the first childNode of all those spans.
(3) convert the nodeValues of those childNodes to numbers (if needed).
(4) search highest value of those numbers.

Gregor

--http://photo.gregorkofler.at::: Landschafts- und Reisefotografiehttp://web.gregorkofler.com*::: meine JS-Spielwiesehttp://www.image2d.com* ** ::: Bildagentur für den alpinen Raum
Thanks. How do I 'Get collection of all spans with className
"prescription"'? - Dave
Aug 4 '08 #4

P: n/a
laredotornado wrote:
On Aug 3, 3:15 pm, Gregor Kofler <use...@gregorkofler.atwrote:
>laredotornadomeinte:
>>On my HTML page, I have a number of SPANs like
<span class="myNumber">3</span>
What I would like is a way to return the maximum number in between the
SPANs. You can assume that if I have an HTML block like the above, I
will also have
<span class="prescriptionNumber">1</span>
<span class="prescriptionNumber">2</span>
somewhere on my page before it.
(1) Get collection of all spans with className "prescription".
(2) Collect the first childNode of all those spans.
(3) convert the nodeValues of those childNodes to numbers (if needed).
(4) search highest value of those numbers.
[...]

Thanks. How do I 'Get collection of all spans with className
"prescription"'?
Google is your friend.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Aug 4 '08 #5

P: n/a
laredotornado <la***********@zipmail.comwrites:
Thanks. How do I 'Get collection of all spans with className
"prescription"'?
There is no single method that does that, so you have to write a
function yourself.
In this case, since you are only looking for "span" elements,
you could use document.getElementsByTagName to get all span
elements in the document, and then run through that and operate
on those with a "className" property containing "prescription".

E.g.
function getPrescriptions() {
var ps = [];
var spans = document.body.getElementsByTagName("span");
for(var i = 0, n = spans.length; i < n; i++) {
var sp = spans[i];
if (/\bprescription\b/.test(sp.className)) {
ps.push(sp);
}
}
return ps;
}

Good luck
/L
--
Lasse Reichstein Nielsen
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Aug 4 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.