delphigetelementsbyclassnametms-web-core

How do I change the css style of a TJSNode item in TMS WEB Core?


Normally when I want to change the style of a component, then I can simply do something like this in Delphi:

Panel1.ElementHandle.style.setProperty('display','none');

But I want to change the style of the first element within Panel1 that has a class of Test. I can get that element using the getElementsByClassName function. The function returns a TJSHTMLCollection object which is basically an array and I can do the following to get the first item out of the array:

Panel1.ElementHandle.getElementsByClassName('Test')[0]

But that returns a TJSNode element and the TJSNode doesn't have a style on it like the ElementHandle does. So I can't do the following as that results in an error because style doesn't exist:

Panel1.ElementHandle.getElementsByClassName('Test')[0].style.setProperty('display','none');

So what can I do if I want to change the style for one of these TJSNode items in the TJSHTMLCollection object?


Solution

  • Okay, I just found out that I can simply cast the TJSNode to a TJSHTMLElement which is what the ElementHandle returns and then I have access to style on it:

    var
      TestElem: TJSHTMLElement;
    begin
      TestElem := TJSHTMLElement(Panel1.ElementHandle.getElementsByClassName('Test')[0]);
      TestElem.style.setProperty('display','none');
    end;