Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get text node

Status
Not open for further replies.

zeert2002

Programmer
Sep 26, 2007
13
0
0
US
Hi, I'm trying to achieve the effect that most browsers except for Safari removed.
I'm trying to grab the actual text node when a user click on a text inside an html page.

function getNode(ev)
{
//When a user clicks on a text, IE and FF will print out '1', while it's supposed to be '3'.
alert(ev.target.nodeType);
}

Is there anyway to do this? Thanks so much.
 
>//When a user clicks on a text, IE and FF will print out '1', while it's supposed to be '3'.
alert(ev.target.nodeType);[/i]
On the face of it the line is for ff. In that case, you can do this.
[tt] alert(ev.target.childNodes[0]?ev.target.childNodes[0].nodeType:'childNodes[0] undefined');[/tt]
For ie, reference properly the ev, and replace target by srcElement.
 
Supplementary Note:
Since text nodes on their own cannot host onclick handler, the line is meant to be in their (immediate) parent container's onclick handler.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top