<div class="menu_item_variant" id="date" onmouseover="mouseIn(this.id)" onmouseout="mouseOut(this.id)">
<a href="dating-advice.html">Dating Coaching & Advice</a>
</div>
hi, could some one help me get the value of 'href' using document.getElementById("date") etc. thanks ! Andy.
You can get the "date" element and then loop through its children:
var elm, href;
elm = document.getElementById("date");
for (elm = elm.firstChild; elm; elm = elm.nextSibling) {
if (elm.nodeName === "A") {
href = elm.href;
break;
}
}
Or actually, I think just about every browser has getElementsByTagName
now, so:
var list, href;
list = document.getElementById('date').getElementsByTagName('a');
if (list.length > 0) {
href = list[0].href;
}
More to explore:
Use elem.children[0].href
.
If there may be other children before the <a>
, you can write elem.getElementsByTagName('a')[0].href
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With