Chrome extension - detect if button on the webpage is clicked [duplicate]

qq328170374 注册会员
6 days ago

getElementsByName exists, which returns a collection of the elements. If you plan to find only one:

document.getElementsByName("hi")[0].setAttribute("value", "my value is high");

Edit: a, HTML there (didn't see that before the edit). No 'hi' element in HTML, possibly in some XML format there is...

dizheng1982 注册会员
6 days ago

not getElementByName but getElementsByName, and it returns array.

chaishian 注册会员
6 days ago

Also, i find that document type must be declared to make getelementsbyname work.

patvice 注册会员
6 days ago

It's getElementsByName . Note the plural. It returns an array-like NodeList of elements with that name attribute.