billhowe schrieb:
> I can't persuade jQuery to match elements using class selectors on xml
> document objects retrieved via $.ajax.
>
> In the following, I run four tests: two expressions with two different
> methods of creating xml. The first method is just to parse a raw string
> with jQuery. The second method obtains the xml through $.ajax. In both
> cases, the XML document is
>
> <?xml version="1.0" encoding="UTF-8"?><doc><foo
> class="fooclass"></foo></doc>
>
> The expressions are basic tag selection $('foo') and class selection
> $('foo.fooclass'). For each test, I just report the size of the returned
> jQuery array. I'd expect to get four alerts: '1','1','1','1'. Instead I
> get '1','1','1','0', which indicates that for the $.ajax case, the simple
> tag selector works, but the class selector does not.
>
> Any ideas as to what may be the problem?
>
> ---------------
> var testxml =
> '<?xml version="1.0" encoding="UTF-8"?><doc><foo
> class="fooclass"></foo></doc>';
>
> function test(expr) {
> alert($(expr, $(testxml)).size());
>
> $.ajax({
> type: "GET",
> dataType: "xml",
> url: "test.xml",
> success: function(xml) {
> alert($(expr,xml).size());
> }
> });
> }
>
> function testboth() {
> test('foo');
> test('foo.fooclass');
> }
>
> $(document).ready(testboth);
Hi,
unlike HTML in XML there is no such thing as a predefined class
attribute with a special meaning. It is just an attribute as any
attribute else. Thus you have to use the attribute selector:
$('[EMAIL PROTECTED]"foo"]')
-- Klaus
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/