How do you detect if an html element can append child nodes?

后端 未结 4 794
感情败类
感情败类 2021-01-11 10:20

I created a custom jquery event called \'loading\' in my application. I want to append a masking element with a spinner, when this event is triggered. I can figure out tha

4条回答
  •  -上瘾入骨i
    2021-01-11 11:21

    You can add child elements, they just won't render. This may sound like a semantic distinction, but it's critical to your problem: the DOM doesn't know whether a particular tag is rendered or not.

    Your best bet is just to check manual:

    var allowChildren = function(elem) {
       return ! (elem.nodeName in { INPUT : true, IMG : true }) ;
    };
    

提交回复
热议问题