![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
| (document.all && document.all(displayFieldID)); |
#2
| |||
| |||
|
|
I am testting the following code in firefox [...] The code works in IE but running in FF it does not go into the loop --- if (typeof currentElement.innerText != "undefined") if this something only IE recognises? I do I change it to work in FF? |
#3
| |||
| |||
|
|
RobG wrote: function getText(el) { if ('string' == typeof el.textContent) return el.textContent; if ('string' == typeof el.innerText) return el.innerText; return el.innerHTML.replace(/<[^>]*>/g,''); } This completely off-topic is, |
|
but programmed this was by Yoda? I know their order doesn't really matter, but I would just think that if (typeof el.textContent == 'string') return el.textContent; would read better. "if (5 == x)" just seems so backwards to me. |
#4
| |||
| |||
|
|
(typeof (x = 'string')) //which is inevitably boolean true // if used in an - if - expression. |

#5
| |||
| |||
|
|
On 2006-10-03 15:58:06 +0200, "Richard Cornford" Richard (AT) litotes (DOT) demon.co.uk> said: (typeof (x = 'string')) //which is inevitably boolean true // if used in an - if - expression. Look what coding in C has done to you ![]() In JavaScript, an assignment operation returns the assigned value, not true of false. Which is why you can write things like : a = b = c = 'value' snip |
|
and this behavior is not altered by and enclosing if(). So the type of (x = 'string') happens to be the value itself, 'string'. |
#6
| |||
| |||
|
|
Touffy wrote: Richard Cornford said: (typeof (x = 'string')) //which is inevitably boolean true // if used in an - if - expression. and this behavior is not altered by and enclosing if(). So the type of (x = 'string') happens to be the value itself, 'string'. In an - if - statement the value of the expression (string in this case, as typeof operations always evaluate as strings) is internally type-converted to boolean in order to determine how the - if - expression will act. The - typeof - operator always returns non-empty strings, and non-empty strings type-convert to boolean true. So if the construct is placed in the expression of an - if - statement the effect in terms of controlling the flow within the code will be identical to placing - true - directly in that context |
#7
| |||
| |||
|
|
Richard Cornford said: Touffy wrote: Richard Cornford said: (typeof (x = 'string')) //which is inevitably boolean true // if used in an - if - expression. and this behavior is not altered by and enclosing if(). So the type of (x = 'string') happens to be the value itself, 'string'. In an - if - statement the value of the expression (string in this case, as typeof operations always evaluate as strings) is internally type-converted to boolean in order to determine how the - if - expression will act. ... snip Exactly. The effect of if(typeof (whatever)) is the same as if(true). Because Boolean(typeof whatever)==true. However, the mere presence of an if statement does not make (typeof whatever)===true, as your comment suggested. |
#8
| |||
| |||
|
|
innerText is a proprietary IE property, the W3C equivalent (supported by Firefox) is textContent. |
#9
| |||
| |||
|
|
Touffy wrote: Exactly. The effect of if(typeof (whatever)) is the same as if(true). Because Boolean(typeof whatever)==true. However, the mere presence of an if statement does not make (typeof whatever)===true, as your comment suggested. The mere presence of the expression in question in the expression of an - if - statement means that its evaluated result _will_ be internally type-converted to boolean, and the result of that type-conversion _will_ be true. |
|
(typeof (x = 'string')) //which is inevitably boolean true // if used in an - if - expression. |
#10
| |||
| |||
|
|
"if (5 == x)" just seems so backwards to me. Writing the comparison this way around avoids the common error where and assignment operator is used in place of a comparisons operator. |
![]() |
| Thread Tools | |
| Display Modes | |
| |