How do I get the text \"there\" that comes after a tag in an html document:
hellothere
I see that the
Well if you use jQuery there is a sneaky way to get this
x = $("<p><a>hello</a>there</p>")
x.contents()[1]
You can use lastChild and textContent to get it: http://jsfiddle.net/M3vjR/
You have to first get the a attribute innerhtml then take total innerhtml with using substring you can have your there part ..
$(document).ready(function () {
var getA=$("p >a").text();
var getA=getA.length;
var takeTotal=$("p").text();
var result=takeTotal.substring(get);
alert(result);
});
Something like this?
var p = document.getElementsByTagName("p")[0];
alert(p.childNodes[1].textContent)
use this .. http://jsfiddle.net/2Dxy4/
This is your HTML --
<p id="there">
<a>hello</a>
there
</p>
In your JS
alert(document.getElementById("there").lastChild.textContent)
or
alert(document.getElementById("there").childNodes[1].textContent)
You can find children tags of your parent tag:
var pTag = ...
var childNodes = pTag.childNodes;
Finally you can find your text in a text
node after a
node.