...

View Full Version : selection start/end, replace text



BubikolRamios
11-28-2012, 01:56 PM
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):



foo billgates foo


How to replace second foo ?

is this http://stackoverflow.com/questions/4811822/get-a-ranges-start-and-end-offsets-relative-to-its-parent-container realy so complicated,and as said there can't be guarantied it is cross browser ?

rnd me
11-28-2012, 06:23 PM
This seems simple and seems to actually work :



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.

WolfShade
11-28-2012, 07:20 PM
Why can't you do it via RegEx?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum