views:

226

answers:

1

I have the following html code:

<mytag>
      Just Some Text
</mytag> 

And I have this jQuery command

$('mytag').each(function () { alert($(this).html()); });

In all browsers except IE I'm getting the inner HTML, in IE I'm not. Anyone can shed any light on this mystery? I've tested this with IE8, Mozilla, Opera, Chrome and Safari

+5  A: 

Because Internet Explorer doesn't error correct for that particular type of invalid HTML in the same way that the other browsers you have tested the code with do.

I would imagine that you can hack around it (it works for applying CSS) with:

document.createElement('mytag')

… but you would be better off writing HTML (or writing XML and serving it as application/xml).

David Dorward
Unfortunately i don't merely need to apply CSS to this tag. I need to extract it's innerHTML and manipulate it and i DO need to use a customtag.
William Calleja
+1 “custom tags” are not HTML and you cannot reasonably expect them to behave in any particular way in browsers.
bobince
rewrite you custom tags as `<span class="myCustomTag">..</span>`. That way you can search for them and they don't influence the layout.
Marko Dumic
@William — I said the hack will probably work for what you want. I just have no experience of that as I've never used it beyond getting `abbr` to work and have never needed to get the innerHTML of an `abbr` element, only to apply styling.
David Dorward
Thanks for the help everyone.
William Calleja