cómo bucle sobre todas las etiquetas en un xmlJquery - iterar a través de todas las etiquetas XML
tengo un php que genera XMLs como la siguiente
<register>
<name>peter</name>
<age>12</age>
</register>
<register>
<name>mary</name>
<age>20</age>
</register>
por lo que recibo este XML (esto funciona bien)
$.ajax({success: function(xml) {
$(xml).find('register').each (function()
{
alert($(this).find('name').text()) // works fine, shows peter then mary on the next loop of "each"
// But if i dont know the tag names (name,age) for each register ?
// Something like
$(this).nodes().each .... //
alert($(this).tagName); // i wanna show "name" & "age", how can i get the tag names inside each register in my xml sample tree?
});
}});
gracias por su asnwer rápido pero todavía no puedo hacerlo = ((e IM triste ...) en la ayuda de jquery dice var $ kids = $ (e.target) .children(); pero todavía ... que prolly me da algún objeto/matriz con los hijos pero ¿cómo obtengo el tagName de cada uno de los hijos? esto no funcionó $ (esto) .children(). Each (function() {alert ($ (this) .tagName);}); // no funcionó esto tampoco, muestra todos los métodos/att var childs = $ (this) .children(); \t para (clave en niños) alerta (clave); – dedoz
finalmente ... var $ childs = $ (this) .children(); var longitud = $ childs.length; while (length--) alerta ($ childs [longitud] .tagName); muchas gracias – dedoz