FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Fedora User

 
 
LinkBack Thread Tools
 
Old 06-20-2008, 10:42 PM
Mike Wright
 
Default OT: need javascript/DOM help

Bassel Safadi wrote:

On Sat, Jun 21, 2008 at 12:09 AM, Mike Wright <mike.wright@mailinator.com>
wrote:



Are there any javascript/DOM gurus out there who can tell me why the html
page below finds the <p> tag and the <div> tag but ignores the <a> tag.

Below is the html being tested.

=====================

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title>Javascript DOM Experiments</title></head>
<body>

<p id='m'></p>

<a id='a'></a>
<p id='p'></p>
<div id='v'></div>

<script type='text/javascript'><!--//
var d = document;
var m = d.getElementById('m');
var a = d.getElementById('a');
var p = d.getElementById('p');
var v = d.getElementById('v');
var b = '<br />';
m.innerHTML = a+b+p+b+v+b;
//--></script>

</body>
</html>



will it's simple ,
what do you want to get from the getElementById(')?
I mean if you're trying to know what kind of element is it, just to process
it in some how, then you will not get a result from just using the
getElemntByid thing for example:

d.getElementById('p');
will return in Firefox: [object HTMLParagraphElement]
in IE Mac: [object P]

why don't you just specify what you want to get back from it let's say you
may use:

var a = d.getElementById('a').innerText;
by the way adding href="" to the anchor tag will let var a =
d.getElementById('a'); return the href it self, if you still need an output
that looks like:
[object HTMLanchorElement]

tell me and will find a work around for you...


Thanks for your generous offer, Bassel.

I need the node so I can use "nextSibling".

What I'm trying to accomplish is to "display:none" or "display:block"
the following element whenever the <a> is onclicked.


As you pointed out "document.getElementById()" returns not the id, but
the href. (That really puzzles me and differs from the O'Reilly books
on Javascript and Dynamic HTML).


Is this a known bug? If it is I will have to wrap my tags in such a way
that I can find the other node relative to it some other way.


If you have ideas I'm eager and open eared

Mike Wright :m)

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 06-20-2008, 11:10 PM
Mike Wright
 
Default OT: need javascript/DOM help

Mike Wright wrote:

Bassel Safadi wrote:


On Sat, Jun 21, 2008 at 12:09 AM, Mike Wright wrote:

Are there any javascript/DOM gurus out there who can tell me why the
html page below does not behave as expected?


Below is the html being tested.

=====================

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title>Javascript DOM Experiments</title></head>
<body>
<p id='m'></p>
<a id='a'></a>
<script type='text/javascript'><!--//
var d = document;
var m = d.getElementById('m');
var a = d.getElementById('a');


var a = d.getElementById('a').getAttribute('id');
gives me the 'id'. From there I can create the 'id' of the desired tag,
which solves my immediate problem.


I'm still curious as to why the <a> behaves differently???


m.innerHTML = a;
//--></script>
</body>
</html>

var a = d.getElementById('a').innerText;
by the way adding href="" to the anchor tag will let var a =
d.getElementById('a'); return the href it self, if you still need an
output

that looks like:
[object HTMLanchorElement]

tell me and will find a work around for you...


Thanks for your generous offer, Bassel.

I need the node so I can use "nextSibling".

As you pointed out "document.getElementById()" returns not the id, but
the href. (That really puzzles me and differs from the O'Reilly books
on Javascript and Dynamic HTML).


--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 06-20-2008, 11:20 PM
"Bassel Safadi"
 
Default OT: need javascript/DOM help

What I'm trying to accomplish is to "display:none" or "display:block" the following element whenever the <a> is onclicked.


Maybe this will help you to accomplish the flip flop part of your situation

<script type="text/_javascript_">
function flipflop(element){
var foo;
foo = document.getElementById(element);

if(foo.style.display != 'block')
{
foo.style.display = 'block';
}
else
{
foo.style.display = 'none';
}
}
</script>

now you can simply:
<a Flop some thing</a>


if this isn't what you need or if you can't apply the nextSibling thing on the above function, then please tell...
*



As you pointed out "document.getElementById()" returns not the id, but the href. *(That really puzzles me and differs from the O'Reilly books on _javascript_ and Dynamic HTML).



Is this a known bug? *If it is I will have to wrap my tags in such a way that I can find the other node relative to it some other way.

it may be a known bug for Mozilla like browsers

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 06-20-2008, 11:29 PM
"Bassel Safadi"
 
Default OT: need javascript/DOM help

On Sat, Jun 21, 2008 at 1:10 AM, Mike Wright <mike.wright@mailinator.com> wrote:

Mike Wright wrote:


Bassel Safadi wrote:




On Sat, Jun 21, 2008 at 12:09 AM, Mike Wright wrote:




Are there any _javascript_/DOM gurus out there who can tell me why the html page below does not behave as expected?



Below is the html being tested.



=====================



<?xml version='1.0' encoding='UTF-8'?>

<!DOCTYPE html

*PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

*"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head><title>_javascript_ DOM Experiments</title></head>

<body>

<p * id='m'></p>

<a * id='a'></a>

<script type='text/_javascript_'><!--//

var d = document;

var m = d.getElementById('m');

var a = d.getElementById('a');




var a = d.getElementById('a').getAttribute('id');

gives me the 'id'. *From there I can create the 'id' of the desired tag, which solves my immediate problem.



I'm still curious as to why the <a> behaves differently???


I don't know for sure why it behaves like wise but you can find here:
http://www.w3schools.com/HTMLDOM/dom_obj_anchor.asp

a list of properties you can call by using:


var a = d.getElementById('a').Property;
or:

var a = d.getElementById('a').getAttribute('Property');


--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 06-21-2008, 06:16 AM
Tim
 
Default OT: need javascript/DOM help

On Fri, 2008-06-20 at 14:09 -0700, Mike Wright wrote:
> Are there any javascript/DOM gurus out there who can tell me why the
> html page below finds the <p> tag and the <div> tag but ignores the
> <a> tag.
>
> <p id='m'></p>
>
> <a id='a'></a>
> <p id='p'></p>
> <div id='v'></div>

I don't do scripting, but plenty of plain HTML. Just wondering if your
browser is one of those that ignores empty elements? (That sort of
thing, links to empty anchors being ignored, was an old complaint.) If
you added some content, does it start to work.

e.g. <a id="a">something</a>

--
[tim@localhost ~]$ uname -r
2.6.25.6-55.fc9.i686

Don't send private replies to my address, the mailbox is ignored. I
read messages from the public lists.



--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 06-21-2008, 08:47 AM
"Bassel Safadi"
 
Default OT: need javascript/DOM help

I don't do scripting, but plenty of plain HTML. *Just wondering if your


browser is one of those that ignores empty elements? *(That sort of

thing, links to empty anchors being ignored, was an old complaint.) *If

you added some content, does it start to work.



e.g. <a id="a">something</a>




actually he is trying to resolve the* type of element using _javascript_, the browser can say: hey this is a paragraph even if it's empty, and hey this is a div, but he didn't recognize the anchor


--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 

Thread Tools




All times are GMT. The time now is 10:15 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org