473,654 Members | 3,074 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reference other td

JC
hi all

First of all, sorry for my (bad) english,

I have a javascript:

<script type="text/javascript">
<!--
function gointo(td,color ){td.style.curs or='default';td .bgColor=color; }
function gooutoff(td,col or){td.style.cu rsor='default'; td.bgColor=colo r;}
//-->
</script>

and I reference this code in this way:

<td width="7" bgcolor="#AA000 0"></td>
<td width="145"BGCO LOR="#AA0000" onMouseOver="go into(this,'8000 00');"
onMouseOut="goo utoff(this,'aa0 000');" class="myclass" >
<a class="myclass" href="page.php" >page</a></td>
<td width="5" bgcolor="#AA000 0"></td>

to change background's color of second td when the mouse is over this td.
That's ok. But, how i can reference other td (no "this"). I need to change
also the first td and the last td.. Can i do this?

thanks for advance.
Jul 23 '05 #1
5 2993
Bonjour à JC <do**@write.m e> qui nous a écrit :
hi all

First of all, sorry for my (bad) english,

I have a javascript:

<script type="text/javascript">
<!--
function
gointo(td,color ){td.style.curs or='default';td .bgColor=color; }
function
gooutoff(td,col or){td.style.cu rsor='default'; td.bgColor=colo r;} //-->
</script>

and I reference this code in this way:

<td width="7" bgcolor="#AA000 0"></td>
<td width="145"BGCO LOR="#AA0000" onMouseOver="go into(this,'8000 00');"
onMouseOut="goo utoff(this,'aa0 000');" class="myclass" >
<a class="myclass" href="page.php" >page</a></td>
<td width="5" bgcolor="#AA000 0"></td>

to change background's color of second td when the mouse is over this
td. That's ok. But, how i can reference other td (no "this"). I need
to change also the first td and the last td.. Can i do this?

thanks for advance.


for exemple :

<script type="text/javascript">
function chgColor(obj,co lor){
obj.style.curso r='default';
obj.bgColor=col or;
}
function gointo(td, color){
chgColor(td, color);
chgColor(docume nt.getElementBy Id("td1"), color);
chgColor(docume nt.getElementBy Id("td2"), color);
}
function gooutoff(td, color){
chgColor(td, color);
chgColor(docume nt.getElementBy Id("td1"), color);
chgColor(docume nt.getElementBy Id("td2"), color);
}
</script>

and I reference this code in this way:

<td width="7" bgcolor="#AA000 0" id="td1"></td>
<td width="145"BGCO LOR="#AA0000" onMouseOver="go into(this,'8000 00');"
onMouseOut="goo utoff(this,'aa0 000');" class="myclass" >
<a class="myclass" href="page.php" >page</a></td>
<td width="5" bgcolor="#AA000 0" id="td2"></td>

--
Cordialement, Thierry ;-)

Jul 23 '05 #2
Ivo
"JC" <do**@write.m e> wrote
<script type="text/javascript">
<!--
Hiding from older browsers like <!-- this //--> is no longer necessary these
days. All known browsers know about the script tag (whether they execute it
is another matter).
function gointo(td,color ){td.style.curs or='default';td .bgColor=color; }
function gooutoff(td,col or){td.style.cu rsor='default'; td.bgColor=colo r;}
I may be stating the obvious here, but those two functions are exactly the
same!
//-->
</script>

and I reference this code in this way:

<td width="7" bgcolor="#AA000 0"></td>
<td width="145"BGCO LOR="#AA0000" onMouseOver="go into(this,'8000 00');"
onMouseOut="goo utoff(this,'aa0 000');" class="myclass" >
<a class="myclass" href="page.php" >page</a></td>
<td width="5" bgcolor="#AA000 0"></td>

to change background's color of second td when the mouse is over this td.
That's ok. But, how i can reference other td (no "this"). I need to change
also the first td and the last td.. Can i do this?


Funnily enough, with "this". Namely "this.lastSibli ng" is the first td (in
this case) and "this.nextSibli ng" the last. Even, "this.parentNod e" is the
tr in which all td's all contained. If you use these DOM expressions there
is no need to give each table cell its own id.

function gointo(td,color ){
if (td.nextSibling ) // if td is the last in a row, there is no next
td.nextSibling. style.backgroun d="#"+color;
// or change whole tr
td.parentNode.s tyle.background ="#"+color;
}
HTH
Ivo

Jul 23 '05 #3
On Fri, 9 Apr 2004 18:25:52 +0200, Ivo <no@thank.you > wrote:

[snip]
Funnily enough, with "this". Namely "this.lastSibli ng" is the first
DOM nodes don't have a lastSibling property. What you're thinking of is
Node.previousSi bling, and possibly getting confused with Node.lastChild.
td (in this case) and "this.nextSibli ng" the last. Even,
In all likelihood, you'll find that Node.previousSi bling and
Node.nextSiblin g refer to text nodes, not elements. If the HTML is
structured with no whitespace (of any kind) between elements, then
elements will be continuous.
"this.parentNod e" is the tr in which all td's all contained. If you use
these DOM expressions there is no need to give each table cell its own
id.

function gointo(td,color ){
if (td.nextSibling ) // if td is the last in a row, there is no next
td.nextSibling. style.backgroun d="#"+color;
// or change whole tr
td.parentNode.s tyle.background ="#"+color;
}


To the OP: use the following functions to find the first, last and "other"
TD elements

/* Searches the given element's siblings for the
first occurance of a specific type of element.
If a matching node cannot be found, null is
returned.

ref - node reference from which the search will begin
type - name of a HTML element (in uppercase)
*/
function getNextElement( ref, type ) {
var node = ref;

while( node && ( type != node.nodeName )) {
node = node.nextSiblin g;
}
return node;
}

/* Works in exactly the same way as getNextElement( ),
except for the direction of the search.
*/
function getPreviousElem ent( ref, type ) {
var node = ref;

while( node && ( type != node.nodeName )) {
node = node.previousSi bling;
}
return null;
}

/* Searches the given element's children for the
first occurance of a specific type of element.
If a matching node cannot be found, null is
returned.

ref - node reference
type - name of a HTML element (in uppercase)
*/
function getFirstElement ( parent, type ) {
var node = null;

if( parent.firstChi ld ) {
node = parent.firstChi ld;
} else if( parent.childNod es ) {
node = parent.childNod es[ 0 ];
}
return getNextElement( node, type );
}

/* Searches the given element's children for the
last occurance of a specific type of element.
If a matching node cannot be found, null is
returned.

ref - node reference
type - name of a HTML element (in uppercase)
*/
function getLastElement( parent, type ) {
var node = null;

if( parent.lastChil d ) {
node = parent.lastChil d;
} else if( parent.childNod es ) {
node = parent.childNod es[ parent.childNod es.length - 1 ];
}
return getPreviousElem ent( node, type );
}

Ivo's gointo() replacement would then look like this:

function gointo( td, colour ) {
var next = getNextElement( td, 'TD' );

if( next && next.style ) {
next.style.back groundColor = colour;
}
}

To set the first TD, you could add:

var first = getFirstElement ( td.parentNode, 'TD' );

if( first && first.style ) {
first.style.bac kgroundColor = colour;
}

and similarly for the last TD.

Hope that helps,
Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #4
Ivo
"Michael Winter" said
Ivo wrote:
this.lastSiblin g...
DOM nodes don't have a lastSibling property. What you're thinking of
is Node.previousSi bling


Oops, yes, thank you.
In all likelihood, you'll find that Node.previousSi bling and
Node.nextSiblin g refer to text nodes, not elements. If the HTML is
structured with no whitespace (of any kind) between elements, then
elements will be continuous.


Again thanks, I should 've thought of that. But it 's so silly. What in the
name of goodwill would have made the browser bakers think that we would have
a use for those empty nodes? Here is how to remove empty text nodes and make
the various DOMs a bit more compatible:

function removeemptytext nodes(node) {
if( !node ) node=document.b ody;
for (var x = 0; x < node.childNodes .length; x++) {
var child = node.childNodes[x];
if ((child.nodeTyp e == 3)&&(!/\S/.test(child.nod eValue))) {
node.removeChil d(node.childNod es[x]);
x--;
} else if (child.nodeType == 1) {
removeemptytext nodes(child);
}
}
}
removeemptytext nodes();

Running this function may hopefully simplify some other code...
Ivo
Jul 23 '05 #5
Again thanks, I should 've thought of that. But it 's so silly. What in the
name of goodwill would have made the browser bakers think that we would have
a use for those empty nodes?
If you want to unparse the DOM and get the same code back, you need
the newlines. The DOM was not made for HTML only, but for general
documents, and some browser writers follow the DOM more precisely than
others :)
} else if (child.nodeType == 1) {


You might also want to check against nodeType==9 (DOCUMENT_NODE) , as
it can also have element nodes as children.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #6

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

Similar topics

2
13115
by: RU | last post by:
Hi, I am working on a porting project to port C/C++ application from unixware C++, AT&T Standard components to g++ with STL on Linux. This application has been working properly on Unixware/C++/AT&T componets environment. I have been able to compile all modules after making necessary changes in LINUX/gcc/STL environment. We have two templates defined XList and XMap.
110
9899
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object must be an object instead of
11
2189
by: Doug | last post by:
Is there any harm in passing an object into a method with the 'ref' keyword if the object is already a reference variable? If not, is there any benefit?
13
17916
by: Abe Frohnman | last post by:
Hello all, I'm passing a reference to a class into the constructor of a form, like so: public MyForm(int count, ref Area myArea) {...} How can I use myArea outside the constructor? Should I create another Area and assign myArea to it (ie: Area foo = myArea;) or is there a better way? ~AF
4
3400
by: z_learning_tester | last post by:
I'm reading the MS press C# book and there seems to be a contradiction. Please tell me which one is correct, 1 or 2. Thanks! Jeff 1. First it gives the code below saying that it prints 0 then 42. They say that 42 is printed the second time since the value was wrapped in a class and therefore became passed by reference. (sorry for any typos I am a newbie here ;-)
13
2652
by: al.cpwn | last post by:
I get that these two are different int* get() { static int m; return &m; } int& get() {
51
4434
by: Kuku | last post by:
What is the difference between a reference and a pointer?
27
4206
by: David W | last post by:
I'm almost tearing my hair out. A colleague claimed that a null reference can exist, like this: void f( int& p ) { printf( "%d\n", p ); } int main (int argc, char *argv) {
41
3639
by: Summercool | last post by:
Can we confirm the following? also someone said, Java also has "reference" like in C++, which is an "implicit pointer": Pointer and Reference --------------------- I am starting to see what pointer and reference are and how they relate to each other.
275
12246
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
8376
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
8708
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8489
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
7307
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6161
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
5622
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
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2716
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
1596
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.