I need to get all links from an document element. In sample below how
can i get link to "www.google.com " from element with ID="here"
<html>
<head>
<title></title>
<script>
function bla()
{
window.alert("H ELLO");
}
</script>
</head>
<body>
<td id="here">
<a href="http://www.google.com" >Google</a>
</td>
<script>
document.getEle mentById("here" ) ............... .........WHAT?
</script>
</body>
</html>
Please help. 4 23820
On Jun 2, 10:08 am, "Miroslav Stampar [MCSD.NET / Security+]"
<miroslav.stam. ..@gmail.comwro te:
I need to get all links from an document element. In sample below how
can i get link to "www.google.com " from element with ID="here"
[...]
<body>
<td id="here">
<a href="http://www.google.com" >Google</a>
</td>
<script>
document.getEle mentById("here" ) ............... .........WHAT?
</script>
Assuming that you have valid HTML, the trivial solution is:
var hereTd = document.getEle mentById('here' );
var hereHref = hereTd.getEleme ntsByTagName('a ')[0].href;
--
Rob
Hi
I need to get all links from an document element. In sample below how
can i get link to "www.google.com " from element with ID="here"
RobG's solution should work fine. However, if you have a big list of
urls on the page and you want them all, you need to do this...
var links = document.getEle mentsByTagName( "a");
for(var i = 0; i<links.length ; i++) {
//Do whatever you want with the links
alert(links[i].href)
} http://developer.mozilla.org/en/docs...mentsByTagName
- getElementsByTa gName() Reference
--
Binny V A http://www.openjs.com/ - JavaScript, Opened
On Jun 2, 10:03 am, BinnyVA <binn...@gmail. comwrote:
HiI need to get all links from an document element. In sample below how
can i get link to "www.google.com " from element with ID="here"
RobG's solution should work fine. However, if you have a big list of
urls on the page and you want them all, you need to do this...
var links = document.getEle mentsByTagName( "a");
for(var i = 0; i<links.length ; i++) {
//Do whatever you want with the links
alert(links[i].href)
}
A caveat is that it you will get all anchors as well ( like <a
name="section3" )
For each document on the parsing stage two collections are being
automatically created:
document.links - with all links so all A with HREF attribute set
document.anchor s - all A with NAME attribute set
IMO on big documents, rather than using a rather resource consuming
getElementsByTa gName it is more straightforward to use these pre-
sorted collection:
var lnk = document.links;
var len = lnk.length;
for (var i=0; i<len; i++) {
// do what you need with
// lnk[i]
}
RobG, you are the man :). I owe you.
Thank you all for your time spent.
RobG je napisao/la:
On Jun 2, 10:08 am, "Miroslav Stampar [MCSD.NET / Security+]"
<miroslav.stam. ..@gmail.comwro te:
I need to get all links from an document element. In sample below how
can i get link to "www.google.com " from element with ID="here"
[...]
<body>
<td id="here">
<a href="http://www.google.com" >Google</a>
</td>
<script>
document.getEle mentById("here" ) ............... .........WHAT?
</script>
Assuming that you have valid HTML, the trivial solution is:
var hereTd = document.getEle mentById('here' );
var hereHref = hereTd.getEleme ntsByTagName('a ')[0].href;
--
Rob
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tor Hovland |
last post by:
I'm trying to transform the document element of incoming xml files, however,
I'm having trouble with namespace references not appearing correctly. Here's
an example input file:
<?xml version="1.0" encoding="utf-8" ?>
<inputdoc xmlns:a="http://www.dummy.org" something="true">
<hello somethingelse="false" />
<foo>
<!-- a comment -->
<bar />
|
by: Andy Fish |
last post by:
Hi,
I'm using XML DOM in Java and I have a function like this
Element makeSomeXml(Document doc) {..}
This returns an Element owned by (but not appended to) the specified
document.
Now, when I call this function, sometimes I want to append the result
|
by: s_m_b |
last post by:
I'm trying to get an <a> element to gain the focus onload, but only get
back 'has no properties'.
Reading through this ng, its clear that unless the element is within a
form, this doesn't happen, but according to the w3 TR on html 4.01, the a
element can take onFocus commands, which to me means you can do
document.getElementById(element).focus() ?
I'm trying to get the focus to a specific paragraph, so the page scrolls to
it on loading,...
|
by: b.dam |
last post by:
I'm trying the following:
function grid() {
this._el = document.createElement("TABLE");
var self = this;
document.addEventListener("onkeydown", function(event)
{self.gridKeyDown(event);}, false);
}
|
by: Dave19 |
last post by:
Hi everybody,
Well I have a svg file as shown below:
<svg width='500' height='550' viewbox='40 40 500 550'
xmlns='http://www.w3.org/2000/svg'>
<image x='40' y='40' width='500' height='550' xlink:href='MapPic.jpg'
xmlns:xlink='http://www.w3.org/1999/xlink ' />
</svg>
| |
by: BizTalk Benjamin |
last post by:
Hi, I have an XmlDocument loaded from a memory stream. I set the document
element prefix in this way
XmlElement e = xDoc.DocumentElement;
e.Prefix = "abc"
When i simply write the document element to the command line it shows the
prefix. However, it does not persist in the XmlDoc so when i save the XmlDoc
into a file, the prefix is no longer there.
|
by: pbd22 |
last post by:
hi.
i keep getting this error.
as i understand it, my xml isn't formatted correctly.
the online errata suggests the standard formatting
to solve this problem:
element
(tab) (tab) element
|
by: pbd22 |
last post by:
Hi.
I have an event handler in VB.NET that gets called several times.
The output of the event handler is XML that is being called by
an xmlhttp request from the client.
I am using a stringbuilder to create the XML document by
appending the various parts:
sbhtml.Append("<Some XML Tag>")
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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
|
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...
| |