<?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 :-/开发者_StackOverflow
thanks Rob
If it is a root node, use .filter()
instead of .find()
.
var records = $(xml).filter(":first").attr("rows");
- http://api.jquery.com/filter/
jQuery's .find()
selects by searching inside the root nodes, while .filter()
selects from among the root nodes.
Try
var records = $(xml).find("data").attr("rows");
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:
selecting root element in jquery
After that .attr("rows") should work.
精彩评论