Question : How do I obtain an anchor's attribute value via javascript

Ok, so I've got an ASP.NET TreeView Control which I have all wired up to catch a client-side click event.  Now I want to figure out the Value of the clicked node.

My nodes are rendering as (simplified):


       
        of the
.  I understand I'll have to use a substring to get the specific "289" I want, however how do I get a reference to the corresponding anchor from the input reference I already have from 'window.event.srcElement;'?

Answer : How do I obtain an anchor's attribute value via javascript

Try using the element's nextSibling property

function TreeViewOnClick() {
            var item = window.event.srcElement;
            if(item.tagName == 'INPUT' && item.type == 'checkbox') {
                    // a checkbox has been clicked
                    // now get the value from the corresponding anchor tag
                    // ...Here...
                    var hrefProp = item.nextSibling.getAttribute("href");
            }
}

Keep in mind that you may end up getting returned a text node and will need to check for this.
Random Solutions  
 
programming4us programming4us