textnode

JS DOM: Get elements by text content

懵懂的女人 提交于 2019-11-28 07:37:34
I am looking for a way to perform fulltext search on the DOM tree with JS. In two words, I would like to retrieve the list of text nodes which contain a given string. I've tried mootools' Element.getElements ( ':contains[string]' ) but I can't get it to work with strings containing whitespace. EDIT: jQuery and mootools seem to have their :contains operators work through tree traversal. This would mean that there is no native way for searching the page, is this correct? Seems very inefficient if the page is huge and the only info you have about your element is the string being searched for. Am

How do I select an XML node with the longest child #text node value with XPath?

℡╲_俬逩灬. 提交于 2019-11-28 04:07:27
问题 I've used XPath to select the node with the largest integer id value before using this query: //somenode[not(@id <= preceding::somenode/@id) and not(@id <= following::somenode/@id)] I was hoping that I could do something similar like: //entry[not(string-length(child::text()) <= string-length(preceding::entry/child::text())) and not(string-length(child::text()) <= string-length(following::entry/child::text()))] But it returns a bunch of nodes instead of just one. Sample XML: <xml> <entry>Lorem

JavaScript: Add elements in textNode

╄→гoц情女王★ 提交于 2019-11-27 17:50:26
问题 I want to add an element to a textNode. For example: I have a function that search for a string within element's textNode. When I find it, I want to replace with a HTML element. Is there some standard for that? Thank you. 回答1: You can't just replace the string, you'll have to replace the entire TextNode element, since TextNode elements can't contain child elements in the DOM. So, when you find your text node, generate your replacement element, then replace the text node with a function

jQuery : find and wrap textnode with some element

荒凉一梦 提交于 2019-11-27 06:32:25
问题 my HTML code : <body>Firebrand will tend to burn any bricks out there. so the best idea is to ignore any active firebrand if you are a bricks. Otherwise, you can challenge a firebrand if you have the proper quality to keep up with their latest technology. And don't mess up with firebrand if you are a robber.</body> I want to find any "firebrand" inside the body and replace it with <span class="firebrand">firebrand</span> with jQuery 回答1: Just recurse through the DOM, while using: .replace(/

Is there a 4096 character limit for JavaScript XML text nodes?

允我心安 提交于 2019-11-27 03:27:08
问题 How is it that I always get only the first 4096 chars of a valid XML text node? (using JavaScript...) is a text node limited? 回答1: Yes. Some browsers limit to 4096, and split longer texts into multiple text node children of the parent element. If you look at the source to Apache CXF you will find some utility Java script to deal with this, if no place else. // Firefox splits large text regions into multiple Text objects (4096 chars in // each). Glue it back together. function getNodeText(node

JS DOM: Get elements by text content

杀马特。学长 韩版系。学妹 提交于 2019-11-27 01:54:39
问题 I am looking for a way to perform fulltext search on the DOM tree with JS. In two words, I would like to retrieve the list of text nodes which contain a given string. I've tried mootools' Element.getElements ( ':contains[string]' ) but I can't get it to work with strings containing whitespace. EDIT: jQuery and mootools seem to have their :contains operators work through tree traversal. This would mean that there is no native way for searching the page, is this correct? Seems very inefficient

jQuery select and wrap textNode

瘦欲@ 提交于 2019-11-26 17:51:01
I want to select the text inside the div element and wrap it with a <b> tag. The <b> tag should only wrap to text inside div and not text inside a child element such as the <p> tag in this example. <div>Testing <p>Some more text inside p</p> <p>asdasdasdasdasde p</p> Test </div> I'm able to select the <p> text using the following, but I'm not able to do the same for div . I only want the text of div and not p . For this case it should select and wrap Testing and Test . var x = $('p')[0].textContent; // this is not working for div. console.log(x); JSFiddle You can use contents , and filter by

How to get text node after element?

淺唱寂寞╮ 提交于 2019-11-26 17:47:47
问题 Using jQuery. I have the following html: <input type="checkbox" name='something' value='v1' /> All the world <br /> How would I get ONLY the text. what selector should I use? (I need the "All the world") I also can not touch the HTML... 回答1: Try using the DOM function .nextSibling to pick the next node (including the text nodes) and use nodeValue to get the text All the world $(':checkbox')[0].nextSibling.nodeValue 回答2: Just use the plain-JavaScript nextSibling , though you have to 'drop out

Hide text node in element, but not children

社会主义新天地 提交于 2019-11-26 15:20:36
I'm having a little trouble with CSS and can't seem to find a solution. I have this HTML <div id="closelink"> <a href="">Close</a> Click to close </div> Now I want to hide the text «Click to close» only, without hiding neither the div, nor the link within it. Can this be done? The visibility attribute can be overriden on children elements, so you are able to do this: <div id="closelink"> <a href="">Close</a> Click to close </div> CSS: #closelink { visibility:collapse; } #closelink a{ visibility:visible; } And the result is this: http://jsfiddle.net/pavloschris/Vva84/ .closelink { font-size:

What Is A Text Node, Its Uses? //document.createTextNode()

我们两清 提交于 2019-11-26 12:39:17
问题 So I\'ve been slowly replacing a lot of my normal jQuery code with native javascript, and I happened upon the document.createTextNode() and related MDN documentation. After reading I\'m somewhat confused what a text node is. I understand it can be used to put text inside div \'s, but I\'m sure there\'s a bit more to it than just \"use it to put words inside elements\". Looking at this, it appears a text node can also refer to the text of attributes as well. Can anyone provide a bit more of a