dom-node

How to get the elements bound to a model in Knockoutjs

旧街凉风 提交于 2020-01-05 09:12:16
问题 I want to add a product, find the node an let it flash products = observableArray([]); new_product = new Product(); products.push(new_product); $("tr", new_product.elements).flash(); I tried using afterAdd but it flashed each time I added something. I need to flash only with one of my adding function. The other functions which add should not flash the element. NOTE: flash is a custom JQuery function 回答1: Since an observable can be bound to multiple elements, your best bet is to really come at

How to create NodeList object from two or more DOMNodes

馋奶兔 提交于 2019-12-25 07:00:48
问题 For example I have two DOMNodes: let node1 = document.querySelector('#node-1'); let node2 = document.querySelector('#node-2'); How do I combine them into a NodeList object? Is there an easy solution like array.push(item) ? 回答1: You can add both nodes into a document fragment: var docFragment = document.createDocumentFragment(); docFragment.appendChild(node1); docFragment.appendChild(node2); And if you really want them in a NodeList do: var list = docFragment.querySelectorAll('*'); The down

How can I tell if a text input field dom node does *not* have a selection with javascript?

若如初见. 提交于 2019-12-25 04:49:27
问题 When I check inputFieldDomNode.selectionStart it always returns some number, even if it does not have a text selection and there's no caret in it. So how can I tell if it doesn't have a text selection? 回答1: At least window-globally, you can use Selection.isCollapsed window.getSelection().isCollapsed Despite the compatibility table, I have found it to be working in Chrome, and apparently it's been supported since IE 9 as well. 回答2: You can check if a element is selected with something like:

DOMElement replace HTML value

北慕城南 提交于 2019-12-24 15:26:06
问题 I have this HTML string in a DOMElement : <h1>Home</h1> test{{test}} I want to replace this content in a way that only <h1>Home</h1> test remains (so I want to remove the {{test}} ). At this moment, my code looks like this: $node->nodeValue = preg_replace( '/(?<replaceable>{{([a-z0-9_]+)}})/mi', '' , $node->nodeValue); This doesn't work because nodeValue doesn't contain the HTML value of the node. I can't figure out how to get the HTML string of the node other than using $node->C14N() , but

how to use document.getElementById() in Nodejs

╄→尐↘猪︶ㄣ 提交于 2019-12-20 05:26:24
问题 i'm trying to get elements by id from an html file in a js file using nodejs. I'm getting the error 'document id not defined' because node doesn't provide a document object model by default. So how can i use document.getElementById() in nodejs ? Thank you ! 回答1: If you want to parse files within the same server you should probably use some of this options, because nodejs it's just a JavaScript implementation, There is no window or document object, see this. But to answer exactly your question

How to create a DOMNode in PHP?

…衆ロ難τιáo~ 提交于 2019-12-11 19:54:53
问题 The class DOMNode doesn't provide a contructor and also no static methods like createInstance() . So, how to create an DOMNode instance? 回答1: Create a DOMDocument . It extends from DOMNode, has a constructor, and represents the rootnode of a document. Being a DOMNode, DOMDocument has methods for adding children. For instance, DOMDocument has a method CreateElement, which returns a DOMElement, which also inherits from DOMNode. All in all, it seems that DOMNode is just the base class and

Find index position of a DomNode/Xpath Child Element

╄→гoц情女王★ 提交于 2019-12-11 09:23:19
问题 I am using an xpath expression to determine a certain div-class in my DOM tree (thanks to VolkerK!). foreach($xpath->query('//div[@class="posts" and div[@class="foo"]]') as $node) $html['content'] = $node->textContent; //$html['node-position'] = $node->position(); // (global) index position of the child 'foo' } Eventually I need to know which (global) index position my child 'foo' has, because I want to replace it with jQuery later: eq() or nth-child(). Is there a way to do it? I am following

Modifying element from google.translate.TranslateElement results

早过忘川 提交于 2019-12-10 10:14:52
问题 I'm attempting to embed the very convenient Google Translate translate element into a webpage, which is super simple and works great, but I need to change the default text that displays in the resulting HTML: Having worked with a number of Google APIsand js libraries, I figured this would be no problem as it would almost certainly be configurable, but having looked around for some time I can't find any reference to a property that let's you set this, and documentation in general seems to be

Modifying element from google.translate.TranslateElement results

独自空忆成欢 提交于 2019-12-06 02:35:20
I'm attempting to embed the very convenient Google Translate translate element into a webpage, which is super simple and works great, but I need to change the default text that displays in the resulting HTML: Having worked with a number of Google APIsand js libraries, I figured this would be no problem as it would almost certainly be configurable, but having looked around for some time I can't find any reference to a property that let's you set this, and documentation in general seems to be pitiful. The basic code is: <div id="google_translate_element"></div> <script> function

Check if variable is a valid node element

99封情书 提交于 2019-12-05 14:24:39
问题 How can I change a JS element to see if it is a node or an empty variable? 回答1: It depends on what you mean by an empty variable. If you mean it hasn't had a value assigned, you can check for undefined alert( someVariable !== "undefined" ); Or if you know it has a value, and need to see if it is an element, you could do something like this: alert( someVariable && someVariable.nodeType ); Or if you need to verify that it is a type 1 element, you could do this: alert( someVariable &&