Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
521 views
in Technique[技术] by (71.8m points)

javascript - How to access HTML element using XPath in IE8?

I am stuck with as issue of accessing HTML element in IE using XPath in Javascript? I already tried with selectNodes() method but its for XML only, it does not work for XPath of HTML element.

document.setProperty("SelectionLanguage", "XPath");
var mydoc=document.loadXML(document);
var nodes=mydoc.selectNodes("//input[@name='action']");

But its not returning any element. Can anyone suggest me how to access HTML element in IE by XPath using Javascript? Any suggestion is appreciated.

-Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

you can try the following ,

Browsers can use the following to get all elements with a given tag, regardless of namespace, if the document is served as application/xhtml+xml or other XML type:

    var titles = document.getElementsByTagNameNS("*","input[@name='action']");  

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...