Jquery cannot read custom tag text on Internet Exp

2019-05-09 23:54发布

I would like to use custom tag into my html page and use jquery to read the text in it, something like :

<desc>Hello world</desc>

then with jquery I read the text with :

desc_text=$("desc").first().text();

On firefox and Chrome, it works, I got the 'Hello world', but not with Internet Explorer (IE 9).

After debugging, it seems that the problem comes from IE : <desc> and </desc> are seen as two different DOM nodes. The Hello world is not a child node of <desc>. That's the reason it does not work. If I use the span tag instead of the desc tag : it works.

Is there a way to make it works on IE, or is that normal that IE does not interpret my custom tag like firefox / Chrome ?

2条回答
三岁会撩人
2楼-- · 2019-05-10 00:20

just add on the head of your document

<script>document.createElement('desc');</script>

this is the basic idea also adopted from HTML5shiv to make IE<9 able to properly parse the new HTML5 elements (anyway be aware that you won't be able to inject dinamycally this element via javascript into the DOM)

查看更多
登录 后发表回答