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.
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.
Share Improve this question asked Mar 23, 2011 at 7:37 SmartSolutionSmartSolution 2,3485 gold badges37 silver badges49 bronze badges 3- It might be due to the namespace associated with Html elements.just a guess. – Furqan Hameedi Commented Mar 23, 2011 at 7:39
- @Furqan : Can you please elaborate more on that? – SmartSolution Commented Mar 23, 2011 at 8:04
- the Html rendered in browser has the html tag like this, <html xmlns="w3/1999/xhtml" >, the xmlns attribute specifies the namespace that all html tags belong to , so whenever you want to access some html element, you can do by specifying Namespace before tagname i-e "//xs:input". – Furqan Hameedi Commented Mar 23, 2011 at 8:10
3 Answers
Reset to default 2You might also like this solution to add xpath support for HTML in IE:
http://sourceforge/projects/html-xpath/
This has the benefit of unifying the API between IE and other browsers, as well.
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']");
Try Wicked Good XPath: https://code.google./p/wicked-good-xpath/
It is the smallest and fastest JavaScript-based XPath library and maintained by Google.