JSFiddle - React, Tailwind, and code Playground

by anAgent

HTML

<div class="products">
    <span id="item1">My Item</span>
</div>
<div class="categories">
    <span id="item1">My Item 2</span>    
</div>

JavaScript

$(function() {
    //This will only find the first item with an a duplicate ID
    var $items = $("#item1");
    alert("Only the first item: " + $items.text());

    //This will find each duplicate id
    var $items = $("#item1", ".products");
    alert("Products Item: " + $items.text());
    
    var $items = $("#item1", ".categories");
    alert("Category Item: " + $items.text());
});