11
votes

jquery obtenir tous les identifiants sur la page

est-il possible d'obtenir un tableau constitué de tous les identifiants sur une page avec jQuery?


0 commentaires

3 Réponses :


19
votes

Vous pouvez le faire:

var ids = new Array();
$('[id]').each(function() { //Get elements that have an id=
  ids.push($(this).attr("id")); //add id to array
});
//do something with ids array


1 commentaires

RE: Firebug - $ ("Corps [ID] ') pourrait être une meilleure option, alors, si on peut être certain que nous ne voulons pas tête éléments ou le Comme.



7
votes

Je pense que cela fonctionnerait

var array = [];
$("*").each(function(){
    if(this.id) array.push(this.id);
});


0 commentaires

9
votes
var ids = $('*[id]').map(function() {
    return this.id;
}).get();

  The .map() method is particularly
  useful for getting or setting the
  value of a collection of elements.
http://api.jquery.com/map/

1 commentaires

C'est le genre de chose où il est beaucoup plus propre, et à ceux qui ne peuvent pas envelopper la tête autour de cela beaucoup plus laid.