26 lis 2010

Odczyt atrybutów diva

function get_idx(_this_) {
  alert(_this_.id);
  let idx;
  idx=_this_.parentNode.parentNode.firstChild.getAttribute('d_idx');
  alert(idx);
  idx=_this_.parentNode.parentNode.firstChild.
    nextSibling.
    getAttribute('d_idx');
  alert(idx);
  return false;
}
.a { width: 200px; border: 1px solid; height: 40px; float: left; }
.b,.c { border: 1px solid; width: 40px; height: 40px; float: left; }
<div d_idx="1">
  <div d_idx="2">test 123456</div>
  <div d_idx="3">123</div>
  <div><a id="test1" href="#" onClick="get_idx(this)">usuń</a></div>
</div>