Trilium Backend API
    Preparing search index...
    • Method for getting data attributes, for only the first element in the matched set.

      Type Parameters

      Parameters

      • this: Cheerio<T>
      • name: string

        Name of the data attribute.

      Returns unknown

      The data attribute's value, or undefined if the attribute does not exist.

      $('<div data-apple-color="red"></div>').data('apple-color');
      //=> 'red'
    • Method for getting all of an element's data attributes, for only the first element in the matched set.

      Type Parameters

      Parameters

      Returns Record<string, unknown>

      A map with all of the data attributes.

      $('<div data-apple-color="red"></div>').data();
      //=> { appleColor: 'red' }
    • Method for setting data attributes, for only the first element in the matched set.

      Type Parameters

      Parameters

      • this: Cheerio<T>
      • name: string

        Name of the data attribute.

      • value: unknown

        The new value.

      Returns Cheerio<T>

      The instance itself.

      const apple = $('.apple').data('kind', 'mac');

      apple.data('kind');
      //=> 'mac'
    • Method for setting multiple data attributes at once, for only the first element in the matched set.

      Type Parameters

      Parameters

      • this: Cheerio<T>
      • values: Record<string, unknown>

        Map of names to values.

      Returns Cheerio<T>

      The instance itself.

      const apple = $('.apple').data({ kind: 'mac' });

      apple.data('kind');
      //=> 'mac'