且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

选择没有子元素的元素

更新时间:2023-11-24 19:50:58

CSS选择器,但你可以在几行JS:

You can't do it with a regular CSS selector, but you can do it in a few lines of JS:

var element = document.querySelector('#size');
var b = element.querySelector('b');
var text = b ? b.innerText : element.childNodes[0].nodeValue;

console.log(text);