javascript - How to unwrap text from a span in text block? -


so have big <div> block text in it. , word user double-clicks on wrapping in <span> element how can delete span element , return word it's normal place, w/o span wrapping it, whole text return starting position?

edit: sorry absence. here's code of double-click function wraps div, user have double clicked on in span , adds class span. looking that!

function ondoubleclick(){     var selection=window.getselection().getrangeat(0);     var selectedtext=selection.extractcontents();     var span=document.createelement("span");     epic.get(span).addclass('highlightedtext');     span.appendchild(selectedtext);     selection.insertnode(span); } 

enter image description here

this might want, expect evil 'regex in html'-links in comments :p. it's dependent on fact if <div> has text , spans in or many other (sub)children dom-nodes.

var html = $('#mydiv').html(); var new_html = html.replace(new regexp('<span>[uu]ser</span>','gm'),'user'); $('#mydiv').html(new_html); 

if update question can give more precise answer narrow down collisions can happen regex.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -