开发者

How to retrieve an input element and its surrounded span?

For

<span id="" ...>
  <input id="" ...>
开发者_运维知识库

Is there any way to retrieve span id? input element is embedded within span?


document.getElementById("inputId").parentNode;


If you're using jQuery:

$('#input-id').parent().attr('id');

If not:

document.getElementById('input-id').parentNode.getAttribute('id');

EDIT: Ooops - removed extra parentheses after parentNode!


var parentControl = document.getElementByID("id goes here").parentNode;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜