Listing element properties

<< Click to Display Table of Contents >>

Navigation:  CSS properties and classes >

Listing element properties

Example of getting all CSS properties for element

 

function TForm1.GetCurrentCSS(P: TElement): string;
var WL: TCSSWeightList;
    P: TElement;
    i: integer;
    s: string;
begin
  WL := TCSSWeightList.Create(16);
  Result := '';
  while Assigned(P) do
  begin
    WL.Clear;
    HTML4StyleSheet.GetElementSelectors(P, WL, HTML4StyleSheet.Main, 

  [], cmAll, P.Document.ClientWidth, P.Document.DeviceWidth);
    P.Document.Styles.GetElementSelectors(P, WL, P.Documnt.Styles.Main, 

  [], cmAll, P.Document.ClientWidth, P.Document.DeviceWidth);
    { inline style }
    if Assigned(P.SelfStyleSheet) then
      P.SelfStyleSheet.GetElementSelectors(P, WL, P.SelfStyleSheet.Main,

        [], cmAll, P.Document.ClientWidth, P.Document.DeviceWidth);
    for i := 0 to WL.Count - 1 do
    begin
      s := CSSValuetoString(WL[i]^);
      Result := '<div class="prop"><span class="propname">' + 

        copy(s, 1, FindChar(':', s))  + '</span><span class="propvalue">' +
        copy(s, FindChar(':', s) + 1, MaxInt) +'</span></div>' + Result;
    end;
    P := P.Parent;
  end;
  WL.Free;
end;