Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery cannot read custom tag text on Internet Explorer

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 ?

like image 619
Eric Avatar asked Jan 23 '26 11:01

Eric


2 Answers

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)

like image 190
Fabrizio Calderan Avatar answered Jan 26 '26 01:01

Fabrizio Calderan


http://ajaxian.com/archives/adding-custom-tags-to-internet-explorer-the-official-way

like image 42
Max Hudson Avatar answered Jan 26 '26 02:01

Max Hudson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!