Hya,
I would like to run a bit of code only if the focused text-box has a certain ID. Here is my code:
$("input:text").focus(function() {
if ($(this) == $("#divid")) {
//action
}
});
It does not work, I'm not to sure why.
Try comparing by the id directly.
if (this.id === "divid") {
// do something
}
That'll never work because each call to $() returns a new object.
However:
this == $('#divid')[0]
should work. Or, as Kevin B wisely suggests, just see if your element has the "id" in question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With