Matthias...

Attr('href') will give you whatever is contained in the href property. If
you want the "http://otherpage.com"; then that needs to be contained in the
href property. Using the 'domain' property of the document object will give
you the first part:

        <script type="text/javascript">
        <!--
                alert(document.domain);
        //-->
        </script>


andy


-----Original Message-----
From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Matthias Coy
Sent: Friday, December 05, 2008 10:10 AM
To: jquery-en@googlegroups.com
Subject: [jQuery] How to access href-property


Hi there,

how do I access the "href"-property of an anchor-element? I know there is a

$("#idOfAnAnchor").attr("href");

but this only gives me the attribute and not the property. I need the
property, because inside of this property is the full URL. See example:

<a id="idOfAnAnchor1" href="/index.php">Home</a> // on otherpage.com <a
id="idOfAnAnchor2" href="http://somepage.com/index.php";>Home</a>

$("#idOfAnAnchor1").attr("href"); // gives '/index.php', needed is
'http://otherpage.com/index.php'
$("#idOfAnAnchor2").attr("href"); // gives 'http://somepage.com/index.php'

I could use:

var aLink = document.getElementById("#idOfAnAnchor1");
var aHrefProperty = aLink.href;

but where is the jQuery fun in this :) ?

Regards
        Matthias


Reply via email to