1
I’m trying to convert the following code jQuery
unsuccessful for javascript
pure:
$.each($("p"), function(i, el) {
var el = $(el);
el.html(el.html() + " - " + i);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<p>Teste</p>
<p>Teste</p>
<p>Teste</p>
<p>Teste</p>
<p>Teste</p>
What I’ve been able to do so far is:
var elements = document.querySelectorAll("p");
Array.prototype.forEach.call(elements, function(el, i){
var el = el;
var teste = el.innerHTML +=
teste " - " + i;
});
By the way, even in Jquery, more idiomatic would be
$("p").each(
– Isac