473,666 Members | 2,575 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

typeof.currentE lement.innerTex t not working in Firefox?

I am testting the following code in firefox

function fDHTMLPopulateF ields(displayVa luesArray, displayOrderArr ay)
{
var i,
currentElement,
displayFieldID,
currentChild,
nDisplayValues = displayValuesAr ray.length;
for (i=0; i<nDisplayValue s; i++) {
displayFieldID = "div_" + displayOrderArr ay[i] + "ID";
currentElement = (document.getEl ementById
&& document.getEle mentById(displa yFieldID))
|| (document.all
&& document.all(di splayFieldID));
if (typeof currentElement == "object") {
if (typeof currentElement. innerText != "undefined" ) {
currentElement. innerText = displayValuesAr ray[i];
}
else if (
currentElement. firstChild
&& currentElement. removeChild
&& currentElement. appendChild
&& document.create TextNode
) {
while ((currentChild = currentElement. firstChild)) {
currentElement. removeChild(cur rentChild);
}
currentElement. appendChild(
document.create TextNode(displa yValuesArray[i])
);
}
}
}
}

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?

Thanks in advance.

Oct 3 '06 #1
20 9281

ef*****@epitome .com.sg wrote:
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?
innerText is a proprietary IE property, the W3C equivalent (supported
by Firefox) is textContent. You might like to use a function that
works in a wide variety of browsers:

function getText(el)
{
if ('string' == typeof el.textContent) return el.textContent;
if ('string' == typeof el.innerText) return el.innerText;
return el.innerHTML.re place(/<[^>]*>/g,'');
}

where 'el' is a reference to a DOM element.
--
Rob

Oct 3 '06 #2
RobG wrote:
function getText(el)
{
if ('string' == typeof el.textContent) return el.textContent;
if ('string' == typeof el.innerText) return el.innerText;
return el.innerHTML.re place(/<[^>]*>/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.

--
Trond Michelsen
Oct 3 '06 #3
Trond Michelsen wrote:
RobG wrote:
function getText(el)
{
if ('string' == typeof el.textContent) return el.textContent;
if ('string' == typeof el.innerText) return el.innerText;
return el.innerHTML.re place(/<[^>]*>/g,'');
}

This completely off-topic is,
It is not off topic. The topic of the group is javascript and how
javascript code may be written is certainly on topic. Don't let the
subjects of posts fool you, the do not restrict the subsequent
discussion to anything in particular (except by coincidence).
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.
Writing the comparison this way around avoids the common error where
and assignment operator is used in place of a comparisons operator. If
code attempts to assign to a string (or indeed any) literal then the
error happens at that point. While assigning a string value to an
Identifier is legal, and the consequential errors (if spotted at all)
happen elsewhere and may be difficult to attribute to their cause.

Precedence plays a role in this as assignment has higher precedence
than - typeof - which has higher precedence than comparison. So:-

typeof x == 'string'

-is:-

((typeof x) == 'string')

- while:-

typeof x = 'string'

-is:-

(typeof (x = 'string')) //which is inevitably boolean true
// if used in an - if - expression.

Richard.

Oct 3 '06 #4
On 2006-10-03 15:58:06 +0200, "Richard Cornford"
<Ri*****@litote s.demon.co.uksa id:
(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'

or this beautiful one-line Fibonacci formula :

a = b + (b = a) // too bad there must be parens here

and this behavior is not altered by and enclosing if().
So the type of (x = 'string') happens to be the value itself, 'string'.

--
David Junger

Oct 3 '06 #5
Touffy wrote:
On 2006-10-03 15:58:06 +0200, "Richard Cornford"
<Ri*****@litote s.demon.co.uksa id:
(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>

I am aware of this, but the evaluated value of the expression used in
an - if - statement is not the end of the story.
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

Richard.

Oct 3 '06 #6
On 2006-10-03 16:31:10 +0200, "Richard Cornford"
<Ri*****@litote s.demon.co.uksa id:
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
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)===tru e, as your comment suggested.

--
David Junger

Oct 3 '06 #7
Touffy wrote:
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)===tru e, 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.

Richard.

Oct 3 '06 #8
On 2006-10-03 19:46:14 +0200, "Richard Cornford"
<Ri*****@litote s.demon.co.uksa id:
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)===tr ue, 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.
Well, that's not exactly true, is it ? Mere presence in an if() will
not convert the expression (x = 'string'), so why does (typeof (x =
'string')) get converted ? An expression will be converted to a Boolean
by an if() if and only if it's the outermost expression.
I wasn't disputing that, anyway.

*sigh*... it could go on for a while, even without someone making mistakes.

I disagreed (still do) with the most litteral meaning of your earlier comment:
>>>>(typeof (x = 'string')) //which is inevitably boolean true
// if used in an - if - expression.
, not (most of (see above)) what you've said afterwards. The comment
could mean that in some conditions, the following expression becomes
true:

"(typeof (x = 'string')) is inevitably the boolean true"

which translates in pure JavaScript to:

(typeof (x = 'string')) === true

and that's never true, right ?

Since you like precise wording, well, I found it disturbing that you
would write such an ambiguous comment. Don't get me wrong, I like
precise wording too.
--
David Junger

Oct 3 '06 #9
JRS: In article <11************ **********@i42g 2000cwa.googleg roups.com>,
dated Tue, 3 Oct 2006 06:58:06 remote, seen in
news:comp.lang. javascript, Richard Cornford
<Ri*****@litote s.demon.co.ukpo sted :
"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.
But those who write it backwards in order not to make the error of using
an assignment instead of a comparison will know that they must write ==
not just = and so don't need to write it backwards.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demo n.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.
Oct 3 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
13145
by: Jeff | last post by:
Hi! I'm trying to update a number in a document with the following code. It displays a number, a div block with a minus sign and a div block with a plus sign. When I click the plus sign I want the number to add one to itself, and when I press minus I want it to subtract one. This works in Internet Explorer, but nothing happens in Mozilla. Can any bright head here spot what I'm doing wrong? What here might
2
2085
by: Dag Sunde | last post by:
I have the following code fragment in one of my pages: if (typeof document.getElementById('myApplet').getTableAsSDV != 'undefined') { rowBuffer = document.getElementById('myApplet').getTableAsSDV(); } The code above have been working in IE, NS anf Firefox for a long time now, but have suddenly stopped working in IE 6, on WIN XP SP1.
2
4763
by: delraydog | last post by:
I know that innerText is not supported in FireFox and I've found the following code fragment which was originally designed in an HTMLElement prototype for an innerText getter. I do not however want to use the getter approach and want to just get the innerText as follows: var childS = iframe.contentWindow.document.body.childNodes; for(var i=0; i<childS.length; i++) { if(childS.nodeType==1) text+= childS.tagName=="BR" ? '\n' :...
2
1752
by: Deniz Bahar | last post by:
Hi, I'm working with a single linked list and want to delete elements by searching through the list (starting form the HEAD) then finding the element, then doing the following: NewElement = CurrentElement->next; CurrentElement->next = NewElement->next->next; free(NewElement);
13
2644
by: Lyners | last post by:
I have a web page writen in ASP.NET that contains some javascript so that when a user presses a button, or edits a certain field in a datagrid, another cell in the datagrid is filled with a value. My probelm.... when I have the user press the update button (which does a post back that loops through the datagrid and updates a database) the field/cell that is filled by the javascript appears to be blank in my update code, even though I can...
2
9529
by: Srinivasa | last post by:
Hai, I am new to this group. But not to Javascript. I have a problam with innerText in FireFox. I have the code as below. -- var inputArea = document.getElementById("rtsText"); var outputArea = document.getElementById("uniText"); outputArea.innerText = transformInput(inputArea.value); -- I have two elements, a textarea in which user entered RTS text, and a div tag in which the converted Unicode text will be place using
5
4433
by: prawasini | last post by:
hi, I have a code where a value in one of a table cell needs to be populated on a command button click event. Scenario: There is a main window having multiple <DIV>s In one of the Div there is a table havind ID on a concerned cell (initially blank). The div also has a command button. Now once the button is cliked, a popup window should open and the concerned cell (present in the main window) should be populated with a value. code to...
3
1209
by: fulio pen | last post by:
Hello, I have a code that works on both the IE and Opera, but not the Firefox, and I cannot figure out the reason. Following is the page: http://www.pinyinology.com/test/span2.html And following is the code: function chinText()
1
3832
by: xtremebass | last post by:
Hello Bytes, i have a calender program which is created by using Javascript. when i execute that program using Internet Explorer,it works properly but when i tried in Mozilla firefox it didnt worked. Dates of particular year,month not displayed in that calender grids. i have collected that coding from online free resources. Here i have attached code for your reference. please do suggest me how do i display the calender date in grids in...
0
8454
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8878
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8560
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8644
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6200
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5671
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4200
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2776
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.