Guest User

Untitled

a guest
Jun 18th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. <div id="mydiv">
  2. <span id='span1'>
  3. <span id='span2'>
  4. </div>
  5.  
  6. $("#mydiv").find("span");
  7.  
  8. var array = jQuery.makeArray($("#mydiv").find("span"));
  9.  
  10. $("#mydiv").find("span").each(function(){}); //but i cannot really get the id and assign it to an array that is not with in the scope?(or can I)
  11.  
  12. var IDs = [];
  13. $("#mydiv").find("span").each(function(){ IDs.push(this.id); });
  14.  
  15. var IDs = $("#mydiv span[id]") // find spans with ID attribute
  16. .map(function() { return this.id; }) // convert to set of IDs
  17. .get(); // convert to instance of Array (optional)
  18.  
  19. var idarray = $("#myDiv")
  20. .find("span") //Find the spans
  21. .map(function() { return this.id; }) //Project Ids
  22. .get(); //ToArray
  23.  
  24. var arr = $.map($("#mydiv [id]"), function(n, i) {
  25. return n.id;
  26. });
  27.  
  28. var arr = $.map($("#mydiv span"), function(n, i) {
  29.  
  30. var arr = $.map($("#mydiv span[id]"), function(n, i) {
  31.  
  32. var arr = $("#mydiv [id]").map(function() {
  33. return this.id;
  34. });
  35.  
  36. jQuery.fn.getIdArray = function() {
  37. var ret = [];
  38. $('[id]', this).each(function() {
  39. ret.push(this.id);
  40. });
  41. return ret;
  42. };
  43.  
  44. var array = $("#mydiv").getIdArray();
  45.  
  46. $(function() {
  47.  
  48. var oArr = {};
  49. $("*[id]").each(function() {
  50. var id = $(this).attr('id');
  51. if (!oArr[id]) oArr[id] = true;
  52. });
  53.  
  54. for (var prop in oArr)
  55. alert(prop);
  56.  
  57. });
Add Comment
Please, Sign In to add comment