Based on you rcomment, you want to use the reference of what is clicked. So call the function
$('.className').click(randomString);
It will set this to the object, so inside of randomString you can use $(this).text(randomStr);
function randomString() {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz!@#$%^&*()_+";
var string_length = 8;
var randomStr="";
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomStr += chars.substring(rnum,rnum+1);
}
$(this).text(randomStr);
}
$('.className').click(randomString);
1
solved How do I rewrite this javascript in jQuery? [closed]