JQuery IE Selector Bug Fixed

I ran into an odd bug with JQuery/IE/XSLT recently that might help some of you out.

The problem had to do with JQuery selectors. $(“.tag”) worked in FF 3, but didn’t work at all in IE 7. The HTML and Javascript were being loaded asynchronously via Ajax, so I fiddled around with $.getScript(), callback functions, setTimeout(), etc. to try to give IE time to “find” the tags that I wanted to work with. Nothing worked.

It turns out that the problem was the generated HTML that was being returned from the Ajax call. I was using an XSLT stylesheet to transform some data and had a little section like this:

<xsl:element name="div">
<xsl:attribute name="class">
<xsl:attribute name="foo">
<xsl:value-of select="id"/>
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="value"/>

What was happening was that the XSLT processor (ASP.NET’s XslCompiledTransform, if you’re interested) was spitting out a bunch of whitespace and encoded newlines, which I can’t get WordPress to format correctly or else I’d show you the output.

Firefox could wade through this nonsense to strip out the irrelevant whitespace and carriage returns. IE 7 couldn’t. Fixing up my XSLT to not indent my code for readability (gah) fixed it on IE as well.


0 Responses to “JQuery IE Selector Bug Fixed”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

TwitterCounter for @anthonyrstevens
Add to Technorati Favorites

RSS Feed

View Anthony Stevens's profile on LinkedIn

%d bloggers like this: