0

My code is given below

;(function(window){

    var description_window= document.querySelector('.mg_post_description');

    var $headings= document.querySelectorAll('.mg_blog_main_content h3');

    for (var i = $headings.length - 1; i >= 0; i--) {

        description_window.append($headings[i].cloneNode(true));
    };

})(window);

Can I change the h3 collected from the 'blog_main_contents' to 'p' tags in the target div.

Thanks and regards

2 Answers 2

1

You can iterate through h3's child nodes and append it to new paragraph element:

var paragraph = document.createElement('p');
var headingChildren = $headings[i].cloneNode(true).childNodes;
for (var j = 0; j < headingChildren.length; j++) {
  paragraph.appendChild(headingChildren[j]);
}
description_window.append(paragraph);
Sign up to request clarification or add additional context in comments.

Comments

0

I used insertAdjecentHtml in this example didnt really need jquery.

for (let i = $headings.length - 1; i >= 0; --i) {
   description_window.insertAdjacentHTML("afterbegin","<p>"+ $headings[i].innerHTML + "</p>");
}; 

Here is a working Example.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.