473,689 Members | 2,988 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting active element

if I call javascript like

<a href="javascrip t:;" onmousedown="to ggle('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 2307

"Jon Slaughter" <Jo***********@ Hotmail.comwrot e in message
news:ie******** **********@news svr11.news.prod igy.net...
if I call javascript like

<a href="javascrip t:;" onmousedown="to ggle('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.comwrot e in message
news:ie******** **********@news svr11.news.prod igy.net...
>if I call javascript like

<a href="javascrip t:;" onmousedown="to ggle('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_g o_to_if_javascr ipt_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.com wrote in message
news:68******** *************** *******@comcast .com...
Jon Slaughter wrote:
>"Jon Slaughter" <Jo***********@ Hotmail.comwrot e in message
news:ie******* ***********@new ssvr11.news.pro digy.net...
>>if I call javascript like

<a href="javascrip t:;" onmousedown="to ggle('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(i d, loc)
{
var val = id.parentNode.c hildNodes;
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.com wrote in message
news:68******** *************** *******@comcast .com...
>Jon Slaughter wrote:
>>"Jon Slaughter" <Jo***********@ Hotmail.comwrot e in message
news:ie****** ************@ne wssvr11.news.pr odigy.net...
if I call javascript like

<a href="javascrip t:;" onmousedown="to ggle('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.javas cript 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.com wrote in message
news:68******** *************** *******@comcast .com...
>Jon Slaughter wrote:
>>"Jon Slaughter" <Jo***********@ Hotmail.comwrot e in message
news:ie****** ************@ne wssvr11.news.pr odigy.net...
if I call javascript like

<a href="javascrip t:;" onmousedown="to ggle('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.com wrote in message
news:Cb******** *************** *******@comcast .com...
Jon Slaughter wrote:
>"-Lost" <ma************ ****@techie.com wrote in message
news:68******* *************** ********@comcas t.com...
>>Jon Slaughter wrote:
"Jon Slaughter" <Jo***********@ Hotmail.comwrot e in message
news:ie***** *************@n ewssvr11.news.p rodigy.net...
if I call javascript like
>
<a href="javascrip t:;" onmousedown="to ggle('a');">O</a>
>
is there a way to pass the element a to the function without
specifyin g 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.com wrote in message
news:Cb******** *************** *******@comcast .com...
>Jon Slaughter wrote:
>>"-Lost" <ma************ ****@techie.com wrote in message
news:68****** *************** *********@comca st.com...
Jon Slaughter wrote:
"Jon Slaughter" <Jo***********@ Hotmail.comwrot e in message
news:ie**** **************@ newssvr11.news. prodigy.net...
>if I call javascript like
>>
><a href="javascrip t:;" onmousedown="to ggle('a');">O</a>
>>
>is there a way to pass the element a to the function without
>specifyi ng 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.comwrot e:
[...]
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(i d, loc)
{
var val = id.parentNode.c hildNodes;
If you only want divs, then you might try:

var divs = id.parentNode.g etElementsByTag Name('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.t oLowerCase() == 'div'){
{
if (k == loc) (val[i].style.display == 'none') ?
val[i].style.display = 'block' : val[i].style.display = 'none';
or

val.style.displ ay = (val.style.disp lay == '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
2496
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?? Thanx! Wm <?PHP include('dbconn.php');
4
20224
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. Is i possible to retain that color? My navigation that i'm trying to get this corrected on is server-side include
4
4501
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, visited, focus, hover, active. However: - Mozilla doesn't seem to do anything with the active rule; - IE gets things wrong as usual: it uses the active rule for focus; it ignores the focus rule; - Opera ignores both focus and active rules and...
7
1962
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 with the form data. Under Windowx XP SP2 the IE6 "Information Bar" has the message: "To help protect your security, Internet Explorer has restricted this
1
3891
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 = New DirectoryEntry("LDAP://domain") Dim mySearcher As New DirectorySearcher(enTry) Dim resEnt As SearchResult mySearcher.Filter = ("(objectClass=*)") mySearcher.SearchScope = SearchScope.Subtree
11
4857
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 name that is found on the Workstation Locked screen between the ( )'s. Does anyone know how to do that? The only constraint: no use of ActiveDS.dll permitted by the design. Many thanks! Derek
9
5444
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 anyone who knows if it is possible to 'force' via javascript a status A:active on a link ? I mean: is there a property of the style that can make the css believe a link was clicked when in reality it was not ?
0
1170
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 href="#">Item 3a</a></li>
0
9077
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
8785
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
7623
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
6456
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
5810
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
4548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2965
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
2223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1952
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.