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