質問

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 ?

役に立ちましたか?

解決

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)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top