On May 30, 5:48 am, DaveG <[EMAIL PROTECTED]> wrote:
> How do I find the first text-node of a given DOM object?
>
> Input: here is some text
> Output: " some text"
>
> Input: Header 1
> Output: "Header 1"
I'm not sure what you are really after. If you are after the text
content of an element,
tested.
http://www.w3.org/1999/xhtml"; xml:lang="en">
plainText()
$(function(){
$("div,h1").each(function(){
alert ($(this).plainText().join(""))
})
});
Dave, I was shocked when you got the first answer. I don't think there is
any way to get just the text using jQuery core functions.
If you get .html() you can use regexps to remove the complete nodes, it
seems messy.
if you write a plugin (there may already be one) it can go thru the dom
nodes a
I'm writing this off the top of my head, but it should be at least
close to functional.
jQ: $("#id1").children().filter(function(){return
$(this).text()!="";}).filter(":eq(0)").text()
Or if you intend to use this a lot, you could write a small plugin:
(function($){
$.fn.textNode(index){
index
something like this (untested) returns an array of all the plain text nodes
in a jQuery object.
jQuery.fn.plainText = function() {
var text=[];
this.each(function(){
var children =this.childNodes;
for (var i = 0; i < children.length; i++){
var child = children[i];
I didn't find a way to do this yet, but I did discover a way to crash my
browser:
Warning: locks up FF2
Input: here is some text
jQ: $("#id1<").text()
I also discovered a way to get the text of the first element:
Input: here is some text
jQ: $("#id1>").text()
Output: "here is"
Actually, I withdraw that. .text() returns the text of all nodes combined (in
example 1: "here is some text").
~ ~ Dave
On Tue, 29 May 2007 15:57:55 -0400, DaveG <[EMAIL PROTECTED]> wrote:
>
>
> Indeed it is, thanks. I worked that out after posting -- I figured it had
> to be something incr
Indeed it is, thanks. I worked that out after posting -- I figured it had to be
something incredibly complicated ;)
~ ~ Dave
On Tue, 29 May 2007 14:56:58 -0500, "Jonathan Sharp" <[EMAIL PROTECTED]> wrote:
> I believe it's something like $('div').text();
>
> -js
>
>
> On 5/29/07, DaveG <[E
I believe it's something like $('div').text();
-js
On 5/29/07, DaveG <[EMAIL PROTECTED]> wrote:
How do I find the first text-node of a given DOM object?
Input: here is some text
Output: " some text"
Input: Header 1
Output: "Header 1"
~ ~ Dave
9 matches
Mail list logo