简体   繁体   中英

How do I get DOM elements of which tagnames start with a prefix

Using javascript, how do I get all DOM elements that start with a certain prefix like <prefix:suffix>

Code example:

<div>
    <foo:bar1>hello</foo:bar1>
</div>
<foo:bar2>world</foo:bar2>

But, without looping through ALL elements (for performance reasons)?

Thanks, Ran

With getElementsByTagNameNS :

document.getElementsByTagNameNS("http://example.com/namespace/for/foo", "*");

(Assuming you are using XHTML with elements imported from another namespace and are actually serving it with the correct content-type).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM