开发者

How to retrieve an input element and its surrounded span?

开发者 https://www.devze.com 2022-12-08 11:25 出处:网络
For <span id=\"\" ...> <input id=\"\" ...> 开发者_运维知识库 Is there any way to retrieve span id? input element is embedded within span? document.getElementById(\"inputId\").parentNode;

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

精彩评论

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