I am trying to get at all the 'a' tags surrounded by a div tag with an
id of 'id'
This doesn't seem to do it, picks up all 'a' tags - links=document.getElementsByTagName(id).getElementsByTagName("a");
Any thoughts?
Thanks,
Chris
15 981
Chris wrote:
I am trying to get at all the 'a' tags surrounded by a div tag with an
id of 'id'
This doesn't seem to do it, picks up all 'a' tags - links=document.getElementsByTagName(id).getElementsByTagName("a");
That should give an error as getElementsByTagName gives you a node list
and that node list does not have a getElementsByTagName method.
So you probably want - document.getElementById('id').getElementsByTagName('a')
If that does not work for you as intended then you need to provide more
details of the browser that does not work with.
--
Martin Honnen http://JavaScript.FAQTs.com/
On 21 Jun, 11:49, Martin Honnen <mahotr...@yahoo.dewrote:
Chris wrote:
I am trying to get at all the 'a' tags surrounded by a div tag with an
id of 'id'
This doesn't seem to do it, picks up all 'a' tags
- links=document.getElementsByTagName(id).getElementsByTagName("a");
That should give an error as getElementsByTagName gives you a node list
and that node list does not have a getElementsByTagName method.
So you probably want - document.getElementById('id').getElementsByTagName('a')
If that does not work for you as intended then you need to provide more
details of the browser that does not work with.
--
Martin Honnen http://JavaScript.FAQTs.com/
Thanks Martin,
I am working on a tooltip feature and my problem is that I can't
figure out howto only apply the necessary javascript to relevant links
and not every link on page. If I use
document.getElementById('id').getElementsByTagName ('a')
this works for the first link I wrap in a tag with an id but not the
rest e.g. - <div id="tooltipthis"><a href="" title="">link</a></div>
-
<a href="" title="">No tooltip</a>
-
<div id="tooltipthis"><a href="" title="">link</a></div>
Thanks again,
Chris
Chris wrote:
<div id="tooltipthis"><a href="" title="">link</a></div>
<a href="" title="">No tooltip</a>
<div id="tooltipthis"><a href="" title="">link</a></div>
Ids need to be unique in the complete document so what you have above
can't work.
--
Martin Honnen http://JavaScript.FAQTs.com/
On 21 Jun, 12:37, Martin Honnen <mahotr...@yahoo.dewrote:
Chris wrote:
<div id="tooltipthis"><a href="" title="">link</a></div>
<a href="" title="">No tooltip</a>
<div id="tooltipthis"><a href="" title="">link</a></div>
Ids need to be unique in the complete document so what you have above
can't work.
--
Martin Honnen http://JavaScript.FAQTs.com/
Martin,
Excuse my lack of javascript knowledge...I approach it like a bull in
a china shop.
After a break and some cheese and toast the obvious answer to my
problem was to do getElementByName("tooltip") and work from there.
Thanks again,
Chris
Chris a écrit :
I am trying to get at all the 'a' tags surrounded by a div tag with an
id of 'id'
This doesn't seem to do it, picks up all 'a' tags
links=document.getElementsByTagName(id).getElement sByTagName("a");
Any thoughts?
links=document.getElementById('id').getElementsByT agName('A');
--
sm
Chris wrote:
After a break and some cheese and toast the obvious answer to my
problem was to do getElementByName("tooltip") and work from there.
There is no method named 'getElementByName', only one named
'getElementsByName' however div elements have no attribute named 'name'.
--
Martin Honnen http://JavaScript.FAQTs.com/
Chris a écrit :
> - document.getElementById('id').getElementsByTagName('a')
this works for the first link I wrap in a tag with an id but not the
rest e.g. - <div id="tooltipthis"><a href="" title="">link</a></div>
-
<a href="" title="">No tooltip</a>
-
<div id="tooltipthis"><a href="" title="">link</a></div>
this html is wrong : ID can only be unique
CSS :
===== - div { height: 500px; margin: 20px; border: 1px solid }
HTML :
====== - <div id="tooltipthis_1">
-
<a href="#tooltipthis_3" title="">link 1</a>
-
</div>
-
<a href="#" title="">No tooltip</a>
-
<div id="tooltipthis_2">
-
<a href="#" title="">link 2</a>
-
</div>
-
<div id="tooltipthis_3">
-
<a href="#tooltipthis_1" title="">link 3</a>
-
</div>
-
JS :
==== - function getLinks(commonId) {
-
var d = document.getElementsByTagName('DIV');
-
var L = [];
-
for(var i=, S=d.length; i<S; i++)
-
{
-
if(S[i].id &&
-
S[i].id.indexOf(commonId)>=0 &&
-
S[i].getElementsByTagName('A') &&
-
S[i].getElementsByTagName('A').length>0)
-
{
-
var A = S[i].getElementsByTagName('A');
-
for(var k=0, Z=A.length; k<A; k++)
-
{
-
L[L.length] = A[k];
-
}
-
}
-
}
-
return L;
-
}
-
window.onload = function() { var T = getLinks('tooltipthis'); };
HTML example of using :
======================= - <button onclick="location = T[0].href;">
-
click first link of tooltipthis
-
</button>
--
sm
SAM a écrit :
>
function getLinks(commonId) {
var d = document.getElementsByTagName('DIV');
var L = [];
for(var i=, S=d.length; i<S; i++)
for(var i=0, S=d.length; i<S; i++)
--
sm
Gregor Kofler wrote on 21 jun 2008 in comp.lang.javascript :
for(var i = d.length; i--;) { ... };
or:
var i = d.length; while (i--) { ... };
or:
var i = 0; do { ... } while (d[++i]);
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Gregor Kofler a écrit :
SAM meinte:
>>function getLinks(commonId) { var d = document.getElementsByTagName('DIV'); var L = []; for(var i=, S=d.length; i<S; i++)
for(var i=0, S=d.length; i<S; i++)
Why is S and L uppercase?
Why not ?
(easier for my glasses ?)
or I give upper case to collections, or I do it for the length,
I prefer like that instead of all in lower case.
for(var i = d.length; i--;)
is shorter and perhaps faster, too.
shorter? to write ? surely.
faster ? for JS ? would have to be equal, no ?
--
sm
Evertjan. a écrit :
Gregor Kofler wrote on 21 jun 2008 in comp.lang.javascript:
>for(var i = d.length; i--;) { ... };
or:
var i = d.length; while (i--) { ... };
or:
var i = 0; do { ... } while (d[++i]);
Nothing more ? all was well seen about this ?
Each of you two doesn't have anything more to tell?
ie : a shorter way to get those @#?&! links.
--
sm
SAM meinte:
>Why is S and L uppercase?
Why not ?
Uppercase variable names are supposed to indicate constructors.
or I give upper case to collections, or I do it for the length,
I prefer like that instead of all in lower case.
You can of course use whatever coding conventions you like. But since
you are *giving advices*, it would be smarter to follow best practices.
(Just changing cases for the sake of it, is a wacky concept anyway,
meseems...)
>for(var i = d.length; i--;)
is shorter and perhaps faster, too.
shorter? to write ? surely.
faster ? for JS ? would have to be equal, no ?
Faster. Yes. Since d.length has to evaluated only once.
Gregor
-- http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie http://web.gregorkofler.com ::: meine JS-Spielwiese http://www.image2d.com ::: Bildagentur für den alpinen Raum
Gregor Kofler a écrit :
SAM meinte:
>>for(var i = d.length; i--;)
is shorter and perhaps faster, too.
shorter? to write ? surely. faster ? for JS ? would have to be equal, no ?
Faster. Yes. Since d.length has to evaluated only once.
with :
for(var i=0, L=d.length; i<L; i++)
L is evaluated several times ?
--
sm
SAM meinte:
with :
for(var i=0, L=d.length; i<L; i++)
L is evaluated several times ?
Sorry, my wrong - in this case it's evaluated only once (and therefore
just as fast as the alternative versions).
Gregor
-- http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie http://web.gregorkofler.com ::: meine JS-Spielwiese http://www.image2d.com ::: Bildagentur für den alpinen Raum
Chris wrote:
I am working on a tooltip feature and my problem is that I can't
figure out howto only apply the necessary javascript to relevant links
and not every link on page.
You don't need client-side scripting for tooltips in UAs newer than IE 6;
CSS will do there. (I am not talking about the `title' attribute which has
a different purpose.)
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Luke |
last post by:
Elements with name attribute:
form, input, textarea, a, frame, iframe, button, select, map, meta,
applet, object, param, img (if you know more reply...)
Methods of addresing html elements:...
|
by: phil-news-nospam |
last post by:
In followups by Brian O'Connor (ironcorona) to other posts, he repeats
the idea that using tables in CSS is not something that should be done
because IE doesn't support it. Of course I'm not happy...
|
by: Sonnich |
last post by:
Hi!
I just want a single button on a page (without a form) to be disabled
using JS. My problem is to reach the components/elements on the page.
Like this:
<HTML>
<HEAD>
<SCRIPT...
|
by: Steve |
last post by:
Hi;
I'm working on a demo of using a timer on a web site that is made
visible by making a div visible.
My "PopIn Box" div is empty on the page. Before making it visible I
used javascript to...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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...
|
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...
|
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...
| |