[thelist] DOM - .childNode and How to Target?
Christian Heilmann
codepo8 at gmail.com
Mon Apr 2 09:32:08 CDT 2007
On 4/2/07, jono at charlestonwebsolutions.com
<jono at charlestonwebsolutions.com> wrote:
>
> >
> > As the HTML stands (and provided it doesn't change) you can also
> > change the text inside this cell with:
> >
> > var p = document.getElementById('target-b').getElementsByTagName('td')[2];
> > p.firstChild.nodeValue = 'Email';
> >
> The above works perfectly! Now I am working to make it work as an if
> statement so it will work in both situations - as the login form and as
> teh register form.
>
> Any tips on how to wrap this into a if statement; or a better suggestion
> would be wonderful. For example; I might try something like this)?):
>
> <script type="text/javascript" language="javascript>
> if {
> var p = document.getElementById('target-b').getElementsByTagName('td')[2];
> p.firstChild.nodeValue = 'Email';
> }
>
> if {
> var p = document.getElementById('target-x').getElementsByTagName('td')[2];
> p.firstChild.nodeValue = 'Email';
> }
> </script>
>
> Surely my syntax is (way) off...the above is a shot in the dark - if you
> haven't figured it out; I'm not JS guru. Thanks, any help here and I am
> home free...for another day at least;)
if(document.getElementById('target-b')){
document.getElementById('target-b').getElementsByTagName('td')[2].firstChild.nodeValue
= 'Email';
} else if(document.getElementById('target-x')){
document.getElementById('target-x').getElementsByTagName('td')[2].firstChild.nodeValue
= 'Email';
}
if statements always need a condition
if(something){
} else {
}
--
Chris Heilmann
Book: http://www.beginningjavascript.com
Blog: http://www.wait-till-i.com
Writing: http://icant.co.uk/
More information about the thelist
mailing list