GetElementById but what is an ID?

Post Reply
PioPio
Posts: 28
Joined: Sun Nov 05, 2017 10:25 pm

GetElementById but what is an ID?

Post by PioPio » Thu Jul 16, 2020 4:07 pm

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

User avatar
salvadordf
Posts: 2498
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: GetElementById but what is an ID?

Post by salvadordf » Thu Jul 16, 2020 4:42 pm

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

PioPio
Posts: 28
Joined: Sun Nov 05, 2017 10:25 pm

Re: GetElementById but what is an ID?

Post by PioPio » Thu Jul 16, 2020 5:01 pm

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

User avatar
salvadordf
Posts: 2498
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: GetElementById but what is an ID?

Post by salvadordf » Thu Jul 16, 2020 5:06 pm

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.

Post Reply