With jQuery, you can use .closest()or .parent()(although the parent view is only 1 level, while it .closest()rises until it finds something). I have always found .closest()it simpler and more reliable, as it will work if you change the layout (i.e. you transfer the material to <span>or something else).
Anyway, here is the jQuery version:
<input type="radio" onlick="var id = $(this).closest('table').attr('id');" />
, JavaScript.
JavaScript:
function findAncestorByTagName(start, tagName) {
if (tagName.toUpperCase() === start.nodeName.toUpperCase()) {
return start;
}
else if (start === document.body) {
return false;
}
else {
return findAncestorByTagName(start.parentNode, tagName);
}
}
onclick, :
<input type="radio" onclick="var par = findAncestorByTagName(this, 'div'); if (par && par.id) { /* use par.id */ }" />