"The output should span, span , div"
Try something like this:
var jj = $('.fa').find('*').map(function() {
return this.nodeName;
}).get().join(", ");
alert(jj);
Demo: http://jsfiddle.net/zwCdZ/
The .get()
method returns an array of elements, and arrays don't have a nodeName
property. To produce the result you asked for (as a string), you need to process each item in the array. I'd suggest using the .map()
method, turning the result into a plain array with the .get()
method, and then joining that array into a string with .join()
.