473,498 Members | 703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting active element

if I call javascript like

<a href="javascript:;" onmousedown="toggle('a');">O</a>

is there a way to pass the element a to the function without specifying any
tags or names?

I want the function to automatically return a "pointer" to the a link that
it was called from instead of having to specify it.

Thanks,
Jon
Jun 16 '07 #1
8 2294

"Jon Slaughter" <Jo***********@Hotmail.comwrote in message
news:ie******************@newssvr11.news.prodigy.n et...
if I call javascript like

<a href="javascript:;" onmousedown="toggle('a');">O</a>

is there a way to pass the element a to the function without specifying
any tags or names?

I want the function to automatically return a "pointer" to the a link that
it was called from instead of having to specify it.

Thanks,
Jon
I think I can just pass this and it will work? (atleast the example I tried
works)
Jun 16 '07 #2
Jon Slaughter wrote:
"Jon Slaughter" <Jo***********@Hotmail.comwrote in message
news:ie******************@newssvr11.news.prodigy.n et...
>if I call javascript like

<a href="javascript:;" onmousedown="toggle('a');">O</a>

is there a way to pass the element a to the function without specifying
any tags or names?

I want the function to automatically return a "pointer" to the a link that
it was called from instead of having to specify it.

I think I can just pass this and it will work? (atleast the example I tried
works)
Hey Jon. A little far from home aren't you? ; )

Anyway, 2 things.

1. Do not use the "javascript:" protocol in links. In fact, do not use
it period unless you are writing a bookmarklet.

2. Yes, you can use "this" as "this" refers intrisicly to the calling
object.

3. There are more appropriate events for a link, for example,
"onclick." Unless of course you specifically need the precision of a
mouse down (as in, do you need mousedown, then mouseup).

An example:

<a href="page_to_go_to_if_javascript_is_disabled.htm"
onclick="toggle(this);">link</a>

Bear this in mind, it passes the link as an object. That is, your
toggle function will need to handle an object. "this" will not pass
just the links name, or href or whatever for example. It will pass the
entire link with properties.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Jun 16 '07 #3

"-Lost" <ma****************@techie.comwrote in message
news:68******************************@comcast.com. ..
Jon Slaughter wrote:
>"Jon Slaughter" <Jo***********@Hotmail.comwrote in message
news:ie******************@newssvr11.news.prodigy. net...
>>if I call javascript like

<a href="javascript:;" onmousedown="toggle('a');">O</a>

is there a way to pass the element a to the function without specifying
any tags or names?

I want the function to automatically return a "pointer" to the a link
that it was called from instead of having to specify it.

I think I can just pass this and it will work? (atleast the example I
tried works)

Hey Jon. A little far from home aren't you? ; )
?
Anyway, 2 things.

1. Do not use the "javascript:" protocol in links. In fact, do not use
it period unless you are writing a bookmarklet.
Why?
2. Yes, you can use "this" as "this" refers intrisicly to the calling
object.

3. There are more appropriate events for a link, for example, "onclick."
Unless of course you specifically need the precision of a mouse down (as
in, do you need mousedown, then mouseup).

Actually I'm not using a link. I jus want to toggle the display state of an
object that is related to some other object. I have done this

function toggleDisplay(id, loc)
{
var val = id.parentNode.childNodes;
var loc = (loc == null) ? 0 : loc;

for (i=0; i<val.length; i++)
{
var k = 0;
if (val[i].nodeName=="DIV")
{
if (k == loc) (val[i].style.display == 'none') ?
val[i].style.display = 'block' : val[i].style.display = 'none';
k++;
}
}
return;
}

Which lets me toggle a div that is a certain sibling of some object. (for
some reason I couldn't get nextSibling to work right(had to use it twice to
get the adjacient div and I guess it had to do with text blocks or
something)).
Anyways, what I'm using does seem to work. I'd rather have used css to do
the toggling but guess thats impossible ;/

Thanks,
Jon
Jun 16 '07 #4
Jon Slaughter said the following on 6/16/2007 3:16 PM:
"-Lost" <ma****************@techie.comwrote in message
news:68******************************@comcast.com. ..
>Jon Slaughter wrote:
>>"Jon Slaughter" <Jo***********@Hotmail.comwrote in message
news:ie******************@newssvr11.news.prodigy .net...
if I call javascript like

<a href="javascript:;" onmousedown="toggle('a');">O</a>

is there a way to pass the element a to the function without specifying
any tags or names?
<snip>
>1. Do not use the "javascript:" protocol in links. In fact, do not use
it period unless you are writing a bookmarklet.

Why?
<URL: http://jibbering.com/faq/index.html#FAQ4_24>

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 16 '07 #5
Jon Slaughter wrote:
"-Lost" <ma****************@techie.comwrote in message
news:68******************************@comcast.com. ..
>Jon Slaughter wrote:
>>"Jon Slaughter" <Jo***********@Hotmail.comwrote in message
news:ie******************@newssvr11.news.prodigy .net...
if I call javascript like

<a href="javascript:;" onmousedown="toggle('a');">O</a>

is there a way to pass the element a to the function without specifying
any tags or names?

I want the function to automatically return a "pointer" to the a link
that it was called from instead of having to specify it.
I think I can just pass this and it will work? (atleast the example I
tried works)
Hey Jon. A little far from home aren't you? ; )

?
Um, we've conversed and I've shared code with you in comp.lang.php.

Damn, am I that forgettable, it was like a week ago?

Oh well...
>Anyway, 2 things.

1. Do not use the "javascript:" protocol in links. In fact, do not use
it period unless you are writing a bookmarklet.

Why?
Mr. Webb has provided you the relevant link.
Anyways, what I'm using does seem to work. I'd rather have used css to do
the toggling but guess thats impossible ;/
"CSS popups" is (I think) the closest thing you'll come to that, but
never a true toggle (with CSS).

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Jun 17 '07 #6

"-Lost" <ma****************@techie.comwrote in message
news:Cb******************************@comcast.com. ..
Jon Slaughter wrote:
>"-Lost" <ma****************@techie.comwrote in message
news:68******************************@comcast.com ...
>>Jon Slaughter wrote:
"Jon Slaughter" <Jo***********@Hotmail.comwrote in message
news:ie******************@newssvr11.news.prodig y.net...
if I call javascript like
>
<a href="javascript:;" onmousedown="toggle('a');">O</a>
>
is there a way to pass the element a to the function without
specifying any tags or names?
>
I want the function to automatically return a "pointer" to the a link
that it was called from instead of having to specify it.
I think I can just pass this and it will work? (atleast the example I
tried works)
Hey Jon. A little far from home aren't you? ; )

?

Um, we've conversed and I've shared code with you in comp.lang.php.

Damn, am I that forgettable, it was like a week ago?

Oh well...
Naw... its just that my memory sucks ;/


Jun 17 '07 #7
Jon Slaughter wrote:
"-Lost" <ma****************@techie.comwrote in message
news:Cb******************************@comcast.com. ..
>Jon Slaughter wrote:
>>"-Lost" <ma****************@techie.comwrote in message
news:68******************************@comcast.co m...
Jon Slaughter wrote:
"Jon Slaughter" <Jo***********@Hotmail.comwrote in message
news:ie******************@newssvr11.news.prodi gy.net...
>if I call javascript like
>>
><a href="javascript:;" onmousedown="toggle('a');">O</a>
>>
>is there a way to pass the element a to the function without
>specifying any tags or names?
>>
>I want the function to automatically return a "pointer" to the a link
>that it was called from instead of having to specify it.
I think I can just pass this and it will work? (atleast the example I
tried works)
Hey Jon. A little far from home aren't you? ; )

?
Um, we've conversed and I've shared code with you in comp.lang.php.

Damn, am I that forgettable, it was like a week ago?

Oh well...

Naw... its just that my memory sucks ;/
Don't feel bad. I have a disability directly related to memory. :(

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Jun 17 '07 #8
On Jun 17, 5:16 am, "Jon Slaughter" <Jon_Slaugh...@Hotmail.comwrote:
[...]
Actually I'm not using a link. I jus want to toggle the display state of an
object that is related to some other object. I have done this

function toggleDisplay(id, loc)
{
var val = id.parentNode.childNodes;
If you only want divs, then you might try:

var divs = id.parentNode.getElementsByTagName('div');
It may not be what you want as it will get all the descendant divs,
not just the direct children of parentNode.

var loc = (loc == null) ? 0 : loc;
If no value is passed to loc, its value will be 'undefined'. So while
the above "works", it isn't strictly true. You may prefer:

var loc = loc || 0;

so that if loc evaluates to false (i.e. it is undefined, false, null
or zero) it will be assigned a value of zero. Otherwise, it is
assigned its current value.
>
for (i=0; i<val.length; i++)
You should keep i local with var, and getting val.length every time is
inefficient, consider:

for (var i=0, len=val.length; i<len; i++)

{
var k = 0;
There's no need to declare k on every loop (it doesn't do any harm,
it's just not necessary), you can declare it outside and just set its
value here.

if (val[i].nodeName=="DIV")
It's better to store values if they are going to be used a number of
times rather than looking them up. Declare val earlier (say at the
start with k), then:

val = val[i];
if (val.nodeName.toLowerCase() == 'div'){
{
if (k == loc) (val[i].style.display == 'none') ?
val[i].style.display = 'block' : val[i].style.display = 'none';
or

val.style.display = (val.style.display == 'none')? '' : 'none';

k++;
}
}
return;
If there is no return value, there's no need for return here.
}

Which lets me toggle a div that is a certain sibling of some object. (for
some reason I couldn't get nextSibling to work right(had to use it twice to
get the adjacient div and I guess it had to do with text blocks or
something)).
Some browsers insert #text nodes to preserve whitespace, e.g. Given
the following HTML:

<div>
<p>
<p>
</div>

in firefox the div will have 3 child nodes (#text, p, p), in IE there
will only be 2 (p, p). So you can happily use nextSibling if you
filter out the nodes you don't want (which is what you are doing with
the childNodes collection).

>
Anyways, what I'm using does seem to work. I'd rather have used css to do
the toggling but guess thats impossible ;/
Not at all, you can add/remove class values or edit the CSS rule
directly, take your pick. Where you do the display:none bit in you
current function, you could add or remove a class instead. It is
frequently used where more than a simple 'hide' is required.
--
Rob

Jun 17 '07 #9

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

Similar topics

6
2480
by: Wm | last post by:
I'm totally clueless on this one -- I'm getting 3 copies of every Email (in plain text, not HTML as expected), from a single mail() line... Can anyone tell me what might be causing the duplicates??...
4
20212
by: crhaynes | last post by:
I'm having trouble with my CSS. My links are black, my hover is orange and my active link is red. When I select a link it turns red but i does not retain that color when the selected page loads. ...
4
4487
by: Stephen Poley | last post by:
The issue of the focus pseudo-class came up a few weeks ago, and I finally got around to trying it out (better late than never ...) The recommended order given for the pseudo-classes is link,...
7
1946
by: McKirahan | last post by:
What is "active content"? My ASP page just returns HTML.... I have a page with an .htm extension that has a form whose action is an ASP page which generates a report after updating a database...
1
3875
by: tangus via DotNetMonster.com | last post by:
Hello all, I'm really struggling with getting some Active Directory code to work in ASP.NET. Can you please provide assistance? I am executing the following code: Dim enTry As DirectoryEntry =...
11
4829
by: Derek Martin | last post by:
Using VB.Net, I would like to retrieve the currently logged in user's DN from Active Directory. Alternatively, if, using WindowsIdentity, or something similar, I would like to get the user's full...
9
5407
by: newcomsas | last post by:
Hello. I'm working on a problem related with CSS and javascript: I have got a link on a page and a stylesheet file that makes the background color change when users click on it. Is there...
0
1156
by: Mark | last post by:
Hi there This is my menu (well part of it; it is generated dynamicaly). <ul> <li><a href="#">Item 1</a></li> <li><a href="#">Item 2</a></li> <li><a href="#">Item 3</a> <ul> <li><a...
0
7124
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,...
0
7163
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,...
0
7200
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...
0
7375
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...
1
4904
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...
0
3090
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...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1416
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 ...
1
651
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.