Page 1 of 1

GetElementById but what is an ID?

Posted: Thu Jul 16, 2020 4:07 pm
by PioPio
Hello Salvador,

Please forgive me because my knowledge of HTML is limited.
The interface ICefDomDocument of CEF4Delphi has the function GetElementById but... what is an element and what is the relevant ID ? How can I find them in a .html page?

Many thanks
Alberto

Re: GetElementById but what is an ID?

Posted: Thu Jul 16, 2020 4:42 pm
by salvadordf
Hi Alberto,

The definition of an "HTML element" according to w3schools is this :
An HTML element is defined by a start tag, some content, and an end tag.
https://www.w3schools.com/html/html_elements.asp

HTML attributes provide additional information about HTML elements :
https://www.w3schools.com/html/html_attributes.asp

The ID is one of the attributes of all the html elements used to identify them in the document. Read this for more information :
https://www.w3schools.com/html/html_id.asp

The DOMVisitor demo loads this forum and tries to find the search box in the upper-right corner. That search box is in fact an INPUT element and you can see it in the HTML file like this :

Code: Select all

<input name="keywords" id="keywords" type="search" maxlength="128" title="Search for keywords" class="inputbox search tiny" size="20" value="" placeholder="Search…">
As you can see, the INPUT element only has a start tag and inside the tag there is an "id" attribute with "keywords" as value.

The w3schools website has lots of useful information and tutorials about HTML and CSS. The links I mentioned belong to this tutorial in case you want to take a look :
https://www.w3schools.com/html/default.asp

Re: GetElementById but what is an ID?

Posted: Thu Jul 16, 2020 5:01 pm
by PioPio
Hi Salvador,

Thanks for your answer. I suppose if there are two different elements with the same id, CEF4Delphi we’ll find the first, am I correct?

Alberto

Re: GetElementById but what is an ID?

Posted: Thu Jul 16, 2020 5:06 pm
by salvadordf
The ID value should be unique in the document.

I guess Chromium would return the first one if there are several elements with the same ID.