I have a page with several text inputs and several buttons. When I click a button I want the value of that button to be inserted at the caret, whichever field the caret is in. Here's my function call so far:
$('li input[type="button"]').click(function(){$('#aTextInput').insertAtCaret($(this).val())});
I want to replace $('#aTextInput')
with the input that actually has the caret in it. Any ideas?
(Here's the insertAtCaret
function, before anyone asks. You probably don't need to look at it unless you're curious.)
Edit:
So I tried this:
jQuery.extend(jQuery.expr[':'], {
focus: "a == document.activeElement"
});
$('li input[type="button"]').click(function(){$('input:focus').insertAtCaret($(this).val())});
But when I click a button, nothing happens at all. Am I implementing this solution wrong?