jQuery and ie8 using id selector does not appear to be working (using 1.5.1)
I'm creating a testimonial rotator that parses an XML file full of testimonials. Each testimonial is assigned a "class" so that pages can specify a class of testimonial to use (e.g. "corporate" or "golf" and have a relevant reference show up.)
The problem is that in IE8 (even with the compatibility meta included) the html within the specific ID's is not changed. I switched to classes to ensure that Chrome worked (Firefox always works.) Below is an example using classes:
$("span.quote").html(""" + $(this).find("quote").text() + ""<br />");
//print each testimonial name, title, and org if exists
$("span.attrib").html("- " + $(this).find("name").text() + "");
$("span.attrib").append(", " + $(this).find("title").text() + "");
$("span.attrib").append(", " + $(this).find("organization").text() + "<br />");
These work in Firefox and Chrome. The code below using the ID selector works only in Firefox, but is my preferred method.
$("#quote").html(""" + $(this).find("quote").text() + ""<br />");
//print each testimonial name, title, and org if exists
$("#attrib").html("- " + $(this).find("name").text() + "");
$("#attrib").append(", " + $(this).find("title").text() + "");
$("#attrib").append(", " + $(this).find("organization").text() + "<br />");
My HTML snippet:
<span id="quote">
"This is the default quote."
</span>
<span id="attrib">
- Default name, default title, default organization
</span>
What is incorrect in this code that IE8 won't correctly swap the quotes out? When I switch the code from the selectors to alerts (just to make sure the parsing loop works) everything works fine.
Any comments are appreciated. At a loss here. Going back to a .NET or Flash project to let this sit a few hours.
Rob
Added more code example:
contents of testimonialflipper_tst.js
var filter_value = new String();
$(document).ready(readfilterXML("golf"));
function readfilterXML(passed_value)
{
filter_value =开发者_运维百科 passed_value;
$.ajax({
type: "GET",
url: "testimonials.xml",
dataType: "xml",
success: parseXml
});
}
function parseXml(xml)
{
var holdclass = filter_value;
// need to seek class within id "quote" like "#quote.class" to find out what it is
//find every testimonial and load the array
$(xml).find("testimonial").each(function()
{
var tempclass = $(this).attr("class");
// $("#error").html(tempclass);
if (tempclass == holdclass) {
$("span#quote").html(""" + $(this).find("quote").text() + ""<br />");
//print each testimonial name, title, and org if exists
$("span#attrib").html("- " + $(this).find("name").text() + "");
$("span#attrib").append(", " + $(this).find("title").text() + "");
$("span#attrib").append(", " + $(this).find("organization").text() + "<br />");
}
});
}
Do you have more than one <span>
with the same id? These id's seem pretty generic if you are going to have multiple quotes in your html.
If you do have multiple identical id's, each browser will break in a different way.
P.S. More code would be helpful.
精彩评论