Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Internet Explorer textNode events

    Hi all.

    I've been searching for a while, but have not come up with anything useful here, on Google, or other forums. My question is regarding block elements having multiple text child nodes, and handling onClick events in Internet Explorer.

    Let's say I have the following HTML:

    Code:
    (snippet)
    ....
    <div id="id1">
    Here is some text
    <a href="some url" id="id2">Here is some text inside a link</a>
    Here is some more text
    </div>
    ....
    (snippet)
    Is there a way in IE (using javascript) to determine on a mouse click which one of the text nodes ('Here is some text' or 'Here is some more text') has been clicked by the user?

    I know Mozilla will consider a text node the target of an event, and IE will not. Is there some variable or object that holds more information about which node was clicked in IE? Or maybe a way to determine which node was clicked based on mouse coordinates?

    I know how to do this for regular tag elements, but not for text nodes.

    Any help or suggestions will be appreciated.

    Thanks in advance,
    -Daniel

  • #2
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    all text nodes should be encased in <span> elements.

    then inMouseDown tage target.srcElement to determine the HTML element you are clicking on.

    Work with the object like that

    i.e

    var clickedON =target.srcElement;
    clickedON.style.backgroundColor = "#efefef";
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<

  • #3
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That definitely works, but the problem is, that I don't have control over the html. The html will be provided by the user, so there is no guarantee that all text will be encapsulated in <span>s.

    That is actually what made me post the question in the first place...
    Do you have other suggestions? I'm looking for a way to do this without modifying the provided html.

    Thanks,
    -Daniel

  • #4
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    parse the wrapping DOM node.

    When you grab a peice of 'text' (i.e. you have a <div>with text in it</div> so

    div.childNodes

    you are grabbing the text.

    the text is 'textNodes' at that point and you can work with them like so.
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<

  • #5
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Right. But what if I have:

    Code:
    <div> text1 <br/> text2 </div>
    The <div> will be the srcElement that will receive the click event. At that point, srcElement.childNodes will contain 3 children: text1, <br/>, and text2.
    srcElement.textNodes will contain: text1, and text2.

    The same event will fire if the user clicks on either of text1 or text2. How can I find out which of those 2 was clicked? As far as I know, the window.event object of the Internet Explorer will not carry any such information.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •