V
V
Vitaly2017-06-16 16:48:53
PHP
Vitaly, 2017-06-16 16:48:53

Moving an element in pure javascript?

Good evening. Help me to understand. There are comments in the form of a list that are displayed like this

<li id="comment-23" level="2" class="comment-1">
     <ul class="children children-23">
          <span></span>
     </ul>
</li>
<li id="comment-24" level="2" class="comment-23">
     <ul class="children children-24">
          <span></span>
     </ul>
</li>

and should come out like this
<li id="comment-23" level="2" class="comment-1">
     <ul class="children children-23">
          <span></span>
          <li id="comment-24" level="2" class="comment-23">
               <ul class="children children-24">
                    <span></span>
               </ul>
          </li>
     </ul>
</li>

That is, it must be inherited. I implemented all this in jquery
$('#comments-list > .commentlist > li').each(function () {
            var parentClass = '.' + $(this).attr('class'),
                parent = '#' + $(this).attr('class')+'>'+'ul'+'>'+'span';
            $(parentClass).insertAfter(parent)
        })

But during the page load, you can see how the dom is being rebuilt. How can I not achieve the same result in pure javascript
Here is what is in javascript
var array = document.querySelectorAll('#comments-list > .commentlist > li');
        array.forEach(function (e) {
            var parentClass = '.' + e.getAttribute('class');
            var parent = '#' + e.getAttribute('class') + '>' + 'ul' + '>' + 'span';
            parentElem = document.querySelectorAll(parent);
            elem = document.querySelectorAll(parentClass);
        });

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
OnYourLips, 2018-11-02
@OnYourLips

sudo update-alternatives --set php /usr/bin/php7.2

K
Konstantin B., 2018-11-02
@Kostik_1993

Why update? Just install the new version and change the site config in nginx

H
hOtRush, 2018-11-02
@hOtRush

sudo update-alternatives --set php /usr/bin/php7.2
sudo update-alternatives --set phar /usr/bin/phar7.2
sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.2
sudo update-alternatives --set phpize /usr/bin/phpize7.2
sudo update-alternatives --set php-config /usr/bin/php-config7.2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question