JFairbanks
asked on
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):
<td>
<input type="checkbox" name="myCheckBox" id="myCheckBox" />
<a href="javascript:__doPostB ack('someN ame','s283 \\289')>
The Node Name
</a>
</td>
I've obtained a reference to the specific node via:
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...
}
}
What I want is the "289" from the href in the <a> of the <td>. 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;' ?
My nodes are rendering as (simplified):
<td>
<input type="checkbox" name="myCheckBox" id="myCheckBox" />
<a href="javascript:__doPostB
The Node Name
</a>
</td>
I've obtained a reference to the specific node via:
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...
}
}
What I want is the "289" from the href in the <a> of the <td>. 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;'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That worked perfectly. I knew it was simple, just couldn't figure it out.
Hmm
this:
<a href="#" id="'someName" title="s283\\289" onClick="__doPostBack(this
The Node Name
</a>
then you can do
var title = theCheck.parentNode.getEle