I would like to change every anchor with class .example-class
and change its href from
href="https://www.example.com/?fsaction=doSomething&id=123"
to
onClick="myFunction('id=123')"
Something along the lines of
$('.example-class').each(function() {
var href = $(this).attr('href');
var idOnly = (href -remove everything before and including id=);
$(this).attr('onclick', "id='" + idOnly + "'")
.removeAttr('href');
});
How can I "remove everything before and including id=" to get just 123
and will this work?