My problem is, I need to change the value of H2 to his own text, but my code are changing all the H2s value to the first H2 text of the page, not their own text.
$(function () {
$('h2').attr('id', document.querySelector("h2").innerText);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.slim.min.js"></script>
<h2>Title 1</h2>
<h2>Title 2</h2>
<h2>Title 3</h2>