jQuery addClass example

Change class name on click in jQuery

HTML

<p contenteditable="true" id="pelement"><b>Hello</b> How are <i>you</i> <span>The world would be <b>cooler without problems</b><span> I dont know what else I could write <b>here!</b></p>

JavaScript

function clickFunctionMouse(){
    	let text = $("#pelement").html();
      //Replace the text with a image. 
    	text = text.replace('<span>The world would be <b>cooler without problems</b><span>', '<img src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png">')
    	//Setting new HTML to Element. But how to get Caret-Position of the new Element?
    	$("#pelement").html(text);
}
$('#pelement').on("input", clickFunctionMouse);