Get jquery class and ID name

1

I have the following situation, I search in an object behind some classes, as we know FIND () returns what is inside the selected class, I use join with find each, traversing the whole object.

But the situation I have, I must list all (IDs and classes) descendants of the find classes, I have to list the names of these classes and ids:

$(objeto).find('.nome1, .nome2').each(function(index, value){


});

Imagine, if you have an ID (id="myname" or class="test" etc) I have to list all this, I have no idea how many descending elements I have, I do not know everyone's name, more than 100 WEB pages within the object ...

I know that if I knew the element type, I could do:

$(this).attr('id');
$(this).attr('class');

What I need is to check the class names and IDs I have in the object ... where I searched with find ...

Someone has a course for me to do this ...

    
asked by anonymous 09.04.2015 / 22:40

1 answer

7

The "*" looks for everything.

If you do not know the classes:

var arrayObjetos = [];

$(objeto).find('*').each(function(){
    var classe = $(this).attr("class");
    var id = $(this).attr("id"); 
    arrayObjetos .push({classe:classe, id:id});
});

If you want to filter even the classes .name1 and .name2:

var arrayObjetos = [];

$(objeto).find('.nome1 *, .nome2 *').each(function(){
    var classe = $(this).attr("class");
    var id = $(this).attr("id"); 
    arrayObjetos .push({classe:classe, id:id});
});

Finally on the console you see the result:

console.log(arrayObjetos);
    
09.04.2015 / 23:44