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 3 of 3
  1. #1
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,963
    Thanks
    120
    Thanked 76 Times in 76 Posts

    selection start/end, replace text

    I have div with contentEditable ="true"
    I can read selection.

    How to replace exact selection If I have forinstance divs innerHTML like(can't do it via regex):

    Code:
    foo billgates foo
    How to replace second foo ?

    is this http://stackoverflow.com/questions/4...rent-container realy so complicated,and as said there can't be guarantied it is cross browser ?
    Last edited by BubikolRamios; 11-28-2012 at 02:38 PM.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,335
    Thanks
    11
    Thanked 588 Times in 569 Posts
    This seems simple and seems to actually work :

    Code:
    var whole=getSelection().getRangeAt().commonAncestorContainer;
    
    whole.innerHTML=whole.innerHTML.replace(/foo([^\s\w])/g,"$1");
    i am not 100% sure how you are doing the replacements, but this code opens the door to reliable string processing.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #3
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Why can't you do it via RegEx?
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".


  •  

    Posting Permissions

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