Categories

jQuery.metadata.get()

Categories: Utilities

jQuery.metadata.get( elem, [options] )Returns: Object

Plugin: jQuery.metadata

Description: Extracts, caches, and returns metadata from an element.

  • jQuery.metadata.get( elem, [options] )

    version added: 1.0

    elem   The element containing the metadata to be extracted.

    options   A set of key/value pairs that define the type of metadata to be extracted. All options are optional.

The jQuery.metadata.get() method is capable of extract data from classes, random attributes, child elements and HTML5 data-* attributes.

Attention: jQuery.metadata.get() could be in conflict with .metaparse(), be sure to prevent conflicts use different modes for these methods.

  • Extract data from element.

    HTML:
    <li id="meta" class="someclass {some: 'data'} anotherclass">...</li>
    Code:
    var data = jQuery.metadata.get( document.getElementById('meta') );
    
    if( data.some && data.some == 'data' )
        alert('It Worked!');
  • type

    version added: 1.0

    Specify the expected locations of metadata for the element. Possible values are 'class': search in the class attribute, 'elem': search for an element inside the element being searched, and 'attr': search in a custom attribute on the element.

    Default: 'class'

  • name

    version added: 1.0

    When type is 'attr', specify the name of the custom attribute for which to search. When type is 'elem', specify the tag name of the element for which to search.

    Default: 'metadata'

  • single

    version added: 1.0

    The name given to the data extracted from the element in the jQuery cache.

    Default: 'metadata'