Created
February 17, 2018 10:41
-
-
Save malikkurosaki/0ef4e2e00d5358a827146f8e5ca17a4b to your computer and use it in GitHub Desktop.
create super simple text editor use content editeble and javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id='edit' >edit jjjjjjjj kkkjmlmlkmlkml klknklnkn<div id="saya">saya</div> <div id="apa">apanya</div></div> | |
<button id="rubah">rubah</button> | |
<div id="result">ini hasil</div> | |
<script> | |
var edit = document.getElementById("edit"); | |
var rubah = document.getElementById("rubah"); | |
var result = document.getElementById("result"); | |
edit.contentEditable = "true"; | |
result.onclick = function(){ | |
var xh = new XMLHttpRequest(); | |
xh.onreadystatechange = function(){ | |
if(this.readyState == 4 && this.status == 200){ | |
edit.innerHTML = this.responseText; | |
} | |
}; | |
xh.open("GET","edit.html",true); | |
xh.send(); | |
}; | |
rubah.addEventListener("click",function(){ | |
if(document.getSelection()){ | |
var a = document.getSelection(); | |
var b = a.getRangeAt(0); | |
var d = b.startOffset; | |
var e = b.endOffset; | |
var c = a.toString(); | |
mh = edit.innerHTML.replace(c,"<div id='a' contenteditable='true' style='color:green;border:1px solid blue;padding:10px;'>" + c + "</div>"); | |
var sx = new XMLHttpRequest(); | |
sx.onreadystatechange = function(){ | |
if(this.readyState == 4){ | |
} | |
}; | |
sx.open("GET","get.php?ee=" + mh,true); | |
sx.send(); | |
} | |
}); | |
var hj = edit.childNodes; | |
for(i = 0;i < hj.length;i ++){ | |
hj[i].onclick = function(){ | |
result.innerHTML = this.id; | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment