Count paragraphs in classic TinyMCE Editor

[ad_1]

Every time a ***<p>*** was created in TinyMCE, a number was added to the side, I tried to use the code below, but the function is not running after the full load of TinyMCE:

function addParagraphNumber() {
var paragraphs = document.querySelectorAll(‘.wp-editor p’);
paragraphs.forEach(function (*paragraph*, *i*) {
var span = document.createElement(‘span’);
span.classList.add(‘paragraph-number’);
span.textContent = (*i* \+ 1) + ‘. ‘;
*paragraph*.insertBefore(span, *paragraph*.firstChild);
        });
    }
    tinymce.on(‘init’, function () {
setTimeout(function () {
addParagraphNumber();
        }, 500);
    });
var editor = document.querySelector(‘.wp-editor’);
editor.addEventListener(‘keyup’, function () {
addParagraphNumber();
    });
});

Any ideas?

[ad_2]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer