I found this code that let´s me traverse through some xml elements:
$(somexml).find('company[id="'+id+'"] customers customer').each(function()
{
var $tmp = $(this);
alert($tmp.attr('customerid'));
});
seems to work pretty good. But since i´m novice at Javascript/Jquery i have some questions:
-
How can i respond to when the find() failed…no matches?
-
Why the ‘$’ before tmp? Why not just var tmp = $(this);
1:
eachreturns the object it’s been called on, that is$(x).eachreturns$(x). So, assign the result of each to a variable and check its length:2:
$tmpinstead of justtmpis a “hungarian” convention to denote jQuery objects. You are not required to use it.