开发者

How can we find the childnode element type in javascript?

I have a table cell and I would like to know if it has a text box inside or simply the span tag in it 开发者_JAVA技巧dynamically using javascrip?


If you want to check whether there's an <input> anywhere inside an element, you could use getElementsByTagName():

if (myTableCell.getElementsByTagName('input').length>=1) {
    ...do something with the input...
}


You can check the tagName attribute

function isInput(el){
  return /input/i.test(el.tagName);
}

or more generic:

function isElType(el,tagname){
   return RegExp(tagname,'i').test(el.tagName);
}
//usage
var isInput = isElType(myElement,'input');


Maybe something similar to this:

cell = document.getElementById('tableCell_ID');

spans = cell.getElementsByTagName( "span" );
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜