FernandoSBS
FernandoSBS

Reputation: 655

javascript - document.activeElement

I have a few inputTextBoxes and I'm using document.activeElement to handle value changes of those inputboxes called by "change()" function of inputBox element.

the problem is when I change the value of one of the inputboxes and then click in another inputbox... the function will get the document.activeElement of the new inputbox and will not work... how to make the function "know" that the one that changed was the previous one?

Upvotes: 3

Views: 6487

Answers (2)

FernandoSBS
FernandoSBS

Reputation: 655

actually it worked!!

I changed from:

editBoxAtual = document.activeElement;

to

editBoxAtual = this;

it worked incredible well! thanks

Upvotes: 0

nickf
nickf

Reputation: 546045

In an element's change() handler, the keyword this will refer to the element which was just changed.

$('#foo').change(function() {
    alert(this.id);  // "foo"
});

Upvotes: 3

Related Questions