document.evaluate

Searching the DOM for multiples of the same string, using XPath

会有一股神秘感。 提交于 2020-01-23 01:01:28
问题 I'm writing a Chrome extension that will search the DOM and highlight all email addresses on the page. I found this to look for at symbols on the page but it only returns correctly when there is one email address, it breaks when there are multiple addresses found. found = document.evaluate('//*[contains(text(),"@")]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0); What is the correct way to have this return multiples if more than one is found? 回答1: If you want

JavaScript: iterating over document.evaluate() XPathResult returns null

大城市里の小女人 提交于 2019-12-25 14:49:31
问题 I am trying to get all objects but it doesn't work. var tmp = document.evaluate("//tr", document, null, XPathResult.ANY_TYPE, null); tmp.iterateNext returns me null; 回答1: If you are working in IE, then you should know that document.evaluate does not exist there (see this similar question and the last couple of paragraphs here). Why not just document.getElementsByTagName("tr"); ? 回答2: In my opinion, using an existing JS libraries such as JQuery is usually more reliable in cases like this. 回答3:

JavaScript: iterating over document.evaluate() XPathResult returns null

丶灬走出姿态 提交于 2019-12-25 14:49:10
问题 I am trying to get all objects but it doesn't work. var tmp = document.evaluate("//tr", document, null, XPathResult.ANY_TYPE, null); tmp.iterateNext returns me null; 回答1: If you are working in IE, then you should know that document.evaluate does not exist there (see this similar question and the last couple of paragraphs here). Why not just document.getElementsByTagName("tr"); ? 回答2: In my opinion, using an existing JS libraries such as JQuery is usually more reliable in cases like this. 回答3:

xpath 1.0 list nodes refferring to current node (links counting)

旧城冷巷雨未停 提交于 2019-12-12 05:58:11
问题 What i try to do : I would like to find the proper xpath to count (or list) links referring to the active node. my context is javascript with following detached dom tree used to query xpath with document.evaluate giving a specific entry point. As an example we will consider //*[@id="n11"] as entry point or active node (the second document.evaluate parameter) here the detached dom tree : <root> <node> <a id="n1"/> <a id="n2"/> <a id="n3"/> <a id="n4"/> <a id="n5"/> <a id="n10"/> <a id="n11"/>

Iterate over framesets with XPath expression in JavaScript?

对着背影说爱祢 提交于 2019-12-12 04:25:59
问题 Why does the following JavaScript, when run in Firefox 3.6.3, delete all FRAMESET elements in a document, but the similar script that instead uses an XPath expression to select the FRAMESET elements, does not? Is document.evaluate() simply unable to match FRAMESET elements? Is there an error in the XPath expression? Is there some other error? Select all FRAMESET elements using method document.getElementsByTagName() (succeeds): var framesets = document.getElementsByTagName('frameset'); for

document.evaluate allways returns null in singleNodeValue on some pages\sites

孤者浪人 提交于 2019-12-07 18:59:36
问题 page: http://h4z.it/View/-20100729_designtea.jpg code to execute in console: document.evaluate("//img",document,null,9,null).singleNodeValue or document.evaluate("//a",document,null,9,null).singleNodeValue or even document.evaluate("//html",document,null,9,null).singleNodeValue result (tested both with Chrome and Firefox): null I thought that page overrided document.evaluate but it shows document.evaluate function evaluate() { [native code] } and delete document.evaluate does not help, so

Extract <svg> element by using document.evaluate()?

£可爱£侵袭症+ 提交于 2019-12-07 08:53:54
问题 I am trying to use document.evaluate() to extract certain child elements out of a <svg> element. But I have problems by just extracting the <svg> itself. I can extract everything up to the <svg> , but no further. For example this works well : document.evaluate('//*[@id="chart"]/div/div[1]/div', document, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue) This gives me (shortened) : <div style="position: absolute; left: 0px; top: 0px; width: 100%; height: 100%;" aria-label="Et

document.evaluate allways returns null in singleNodeValue on some pages\\sites

青春壹個敷衍的年華 提交于 2019-12-06 03:48:46
page: http://h4z.it/View/-20100729_designtea.jpg code to execute in console: document.evaluate("//img",document,null,9,null).singleNodeValue or document.evaluate("//a",document,null,9,null).singleNodeValue or even document.evaluate("//html",document,null,9,null).singleNodeValue result (tested both with Chrome and Firefox): null I thought that page overrided document.evaluate but it shows document.evaluate function evaluate() { [native code] } and delete document.evaluate does not help, so what else can it be which breaks document.evaluate ? The page you show in your question uses an xhtml

XPath element/object is undefined when using document.evaluate

妖精的绣舞 提交于 2019-12-01 20:48:01
问题 How can I fix the regular JavaScript code so it doesn't say "undefined" and displays the value of the input field? The jQuery code works fine and displays the input field value correctly on the same page. Regular JavaScript: var obj = document.evaluate('//html/body/form/div[4]/label/input',document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null); alert(obj.value); JQuery 1.7.1 code: var obj = $('html > body > form > div:nth-child(4) > label > input'); alert(obj.value); 回答1: document

XPath element/object is undefined when using document.evaluate

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 18:28:29
How can I fix the regular JavaScript code so it doesn't say "undefined" and displays the value of the input field? The jQuery code works fine and displays the input field value correctly on the same page. Regular JavaScript: var obj = document.evaluate('//html/body/form/div[4]/label/input',document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null); alert(obj.value); JQuery 1.7.1 code: var obj = $('html > body > form > div:nth-child(4) > label > input'); alert(obj.value); document.evaluate() returns an XPathResult. You can retrieve the element like this: var obj = document.evaluate('//html/body