Tag: attributes

  • Getting all element attribute values with jQuery

    Getting all element attribute values with jQuery

    Here is a little snippet which I have found extremely useful especially when working with XML in Javascript. You can use the following to loop through all of an element’s attributes and store them in an object: [cc lang=”javascript”] var element = $(“#myElement”), attributes = {}; $.each(element.get(0).attributes, function(i, attrib){ attributes[attrib.name] = attrib.value; }); [/cc] So…