Get all attributes of an element using jquery

For example, get all attributes of an element using jquery...

Demo




HTML

<div id="domains-links"> 
        <a href="#" target="_self" title="Htmllion">Htmllion.com</a><br>
        <a href="#" target="_self" title="Google">Google.com</a><br>
        <a href="#" target="_self" title="Wikipedia">Wikipedia.org</a> 
</div>
<br>
<div id="getAttrBox"></div>

CSS

<style>
        #getAttrBox { 
                min-height:20px; 
                border:solid 1px gray; 
                padding:15px;
        }
</style>

Jquery

$(function(){
    $('#domains-links a').click(function() {
        var getAttrs ='';
        $.each(this.attributes, function() {
            // this.attributes is not a plain object, but an array
            // of attribute nodes, which contain both the name and value
            
             getAttrs += this.name +' '+ this.value;
         
        });
            $('#getAttrBox').html(getAttrs);
    });
})
  • Share
  • Copyright 2016 by WebiBeris.com. All Rights Reserved.