Trilium Backend API
    Preparing search index...
    • Method for getting attributes. Gets the attribute value for only the first element in the matched set.

      Type Parameters

      Parameters

      • this: Cheerio<T>
      • name: string

        Name of the attribute.

      Returns string

      The attribute's value.

      $('ul').attr('id');
      //=> fruits
    • Method for getting all attributes and their values of the first element in the matched set.

      Type Parameters

      Parameters

      Returns Record<string, string>

      The attribute's values.

      $('ul').attr();
      //=> { id: 'fruits' }
    • Method for setting attributes. Sets the attribute value for all elements in the matched set. If you set an attribute's value to null, you remove that attribute. You may also pass a map and function.

      Type Parameters

      Parameters

      • this: Cheerio<T>
      • name: string

        Name of the attribute.

      • Optionalvalue: string | ((this: Element, i: number, attrib: string) => string)

        The new value of the attribute.

      Returns Cheerio<T>

      The instance itself.

      $('.apple').attr('id', 'favorite').prop('outerHTML');
      //=> <li class="apple" id="favorite">Apple</li>
    • Method for setting multiple attributes at once. Sets the attribute value for all elements in the matched set. If you set an attribute's value to null, you remove that attribute.

      Type Parameters

      Parameters

      • this: Cheerio<T>
      • values: Record<string, string | null>

        Map of attribute names and values.

      Returns Cheerio<T>

      The instance itself.

      $('.apple').attr({ id: 'favorite' }).prop('outerHTML');
      //=> <li class="apple" id="favorite">Apple</li>