function getCursorPosition(parent) {
let selection = document.getSelection()
let range = new Range
range.setStart(parent, 0)
range.setEnd(selection.anchorNode, selection.anchorOffset)
return range.toString().length
}
function setCursorPosition(parent, position) {
let child = parent.firstChild
while(position > 0) {
let length = child.textContent.length
if(position > length) {
position -= length
child = child.nextSibling
}
else {
if(child.nodeType == 3) return document.getSelection().collapse(child, position)
child = child.firstChild
}
}
}
<body>
<p class="text">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Consequuntur laudantium commodi corporis, sunt repellendus impedit quo veritatis reiciendis. Deleniti sequi cumque id animi cupiditate, cum maiores eaque minus maxime itaque.</p>
</body>
<script>
let text = document.querySelector('.text')
text.innerHTML = text.innerHTML.slice(0, 16) + "..."
</script>
<!doctype html>
<html lang="en">
<body>
<button id="search">Search with Google</button>
</body>
<script>
document.getElementById("search").onclick = function() {
var window = window.open("https://www.google.com", "_blank", "toolbar = yes, top = 500, left = 500,
width = 400, height = 400");
window.focus();
};
</script>
</html>
$('#result').html(data);Вы заменяете всю разметку новой.
$('#result').html($('#result').html() + data)
document.querySelector('input[type="file"]').addEventListener('change', function() {
if (this.files.length > 0) {
var file_name = 'Новое название.jpg';
if (this.files[0].name !== file_name) {
var new_file = new File([this.files[0]], file_name, {type: this.files[0].type});
new_file.name = file_name;
var dt = new DataTransfer();
dt.items.add(new_file);
this.files = dt.files;
}
}
});
setTimeout(myFunction, 1000) // вызовет функцию myFunction через 1000 миллисекунд (1 сек)
setTimeout(myFunction, 60000) // вызовет через 10 минут