Nov 21, 2024, 12:23 pm

News:

Вышло обновление win версии


Курсов в конец

Started by Lisa, Sep 22, 2020, 11:32 pm

Previous topic - Next topic

Lisa

пример

<div contenteditable="true">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae quo ratione assumenda quam deserunt, a corporis vero ipsum vitae, id libero veniam error ipsa. Magnam molestiae sapiente delectus modi odio.</div>

<button>Click me!</button>

const div = document.querySelector('div');

document.querySelector('button').addEventListener('click', () => {
    const range = document.createRange();
    range.selectNodeContents(div);
    range.collapse(false);
    const sel = window.getSelection();
    sel.removeAllRanges();
    sel.addRange(range);
});


const div = $('div').get(0); // или $('div')[0];

 $('button').on('click', () => {
    const range = document.createRange();
    range.selectNodeContents(div);
    range.collapse(false);
    const sel = window.getSelection();
    sel.removeAllRanges();
    sel.addRange(range);
 });

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div contenteditable="true">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae quo ratione assumenda quam deserunt, a corporis vero ipsum vitae, id libero veniam error ipsa. Magnam molestiae sapiente delectus modi odio.</div>

<button>Click me!</button>