How to get text node after element?
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
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
All viewable HTML text in a page (except text in form elements or custom embedded objects) is in text nodes. The page consists of a number of different types of nodes (you can see a listing of the different node types here: https://developer.mozilla.org/en-US/docs/Web/API/Node.nodeType), some of which can have child nodes and some of which cannot. … Read more
You can use contents, and filter by node type (3 is for text node): $(‘div’).contents() .filter(function(){return this.nodeType === 3}) .wrap(‘<b />’); Example: http://jsfiddle.net/nJqKq/8 See also: Node Types, at MDC
The visibility attribute can be overriden on children elements, so you are able to do this: #closelink { visibility: collapse; } #closelink a { visibility: visible; } <div id=”closelink”> <a href=””>Close</a> Click to close </div>
Update: I have outlined some basic performance tests for each of these 6 methods over 1000 runs. getElementsByTagName is the fastest but it does a half-assed job, as it does not select all elements, but only one particular type of tag ( i think p) and blindly assumes that its firstChild is a text element. … Read more