JSFiddle - React, Tailwind, and code Playground

HTML

Example 1
<div id="selector"></div>
<div id="selector"></div>

Example 2
<div id="selector2"></div>
<div id="selector2"></div>

CSS

#selector, #selector2 {
    border: 1px solid;
    padding: 10px;
}

JavaScript

$('#selector').each(function() {
  $(this).text('hello, world');  
})

$('#selector:last').after($('#selector').length);


$('[id=selector2]').each(function() {
  $(this).text('hello, world');  
})

$('[id=selector2]:last').after($('[id=selector2]').length);