I'm using PHP8.1 and JQuery.
I have a script with several links that each have an id that is a digit only. i.e:
<a href="#" id="<?= $id ?>"><?= $student_name ?></a>
// <a href="#" id="99">Jane Doe</a>
// <a href="#" id="101">John Smith</a>
Using JQuery I want to know when one of these links is clicked. I'm trying to use a regular expression, but it is not working. I've tried a couple of variations on this, to no avail.
$('a[id^="\d"]').click(function(){
alert("link with digit in id was clicked");
});
I find several posts on doing this when there is some text in the id as well, but none when the id is just a digit.
Thanks for any advice.
clickhandler to a parent object and use the delegated event to handle it. Use thetargetproperty of the event object to determine which link was clicked. See developer.mozilla.org/en-US/docs/Learn_web_development/Core/…