JSFiddle - React, Tailwind, and code Playground

HTML

<div id="myDiv">
    <a href="#" id="myId-test">Click here</a>
</div>

JavaScript

$('#myDiv > a').on("click", function (e) {
    try {
        var count = $('[id^="myId-"').length;
        alert('Count is: ' + count);
    }
    catch(error) {
        alert('Error: ' + error)
    }
});