Get all HTML Attribute's value by Attribute Name Using Jquery

This code will help you to get all the HTML attribute's value using HTML attribute name.
  1. var AllElement=jQuery("Body *");  
  2. var TotalElementInBody=AllElement.length;  
  3. var TotalElementArray=[];  
  4. var TotalElementStr="";  
  5. function GetElementByAttribute(filter){  
  6.     for(var i=0;i<TotalElementInBody;i++){  
  7.         if(typeof (jQuery(AllElement[i]).attr(filter))!="undefined"){  
  8.             if(TotalElementArray.indexOf(jQuery(AllElement[i]).attr(filter))==-1){  
  9.                 TotalElementStr+=jQuery(AllElement[i]).attr(filter)+", ";  
  10.                 TotalElementArray.push(jQuery(AllElement[i]).attr(filter));  
  11.             }  
  12.         }  
  13.     }  
  14. console.log(TotalElementStr);  
  15. }  
Example 1
  1. GetElementByAttribute("class");
Example 2
  1. GetElementByAttribute("id");
Example 3
  1. GetElementByAttribute("src");