tags:

views:

38

answers:

3
<?xml version="1.0" encoding="UTF-8"?>
<data columns="12" rows="0"/>

how can get attributes (rows) of root (data) element in jquery?

i can with

var records = $(xml).find(":first").parent().attr("rows");

but not works :-/

thanks Rob

+3  A: 

If it is a root node, use .filter() instead of .find().

var records = $(xml).filter(":first").attr("rows");

jQuery's .find() selects by searching inside the root nodes, while .filter() selects from among the root nodes.

patrick dw
thanks, works perfect :-)
Roberto
A: 

Try

var records = $(xml).find("data").attr("rows");
Ed
A: 

This might not be working because it is having trouble finding the first element using the query you specified. This might be of some use to you:

http://stackoverflow.com/questions/1650063/selecting-root-element-in-jquery

After that .attr("rows") should work.

Nick Udell