Select element without a child

后端 未结 3 1154
余生分开走
余生分开走 2020-12-20 15:02

I have a page that might one of the following:

33

Or


    <         


        
3条回答
  •  天命终不由人
    2020-12-20 15:43

    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);
    

提交回复
热议问题