Tim Chen Tim Chen - 1 year ago 86
HTML Question

Check when an element has been selected/tabbed onto

I have an HTML page where I have a few

s with
. I also set the
sequentially so when the user hits tab he or she will go through all of the editable
s. However, right now I have "Insert notes here" written inside each of the
s (see below).

<div contenteditable="true" tabindex='1'>Insert notes here<div>
<div contenteditable="true" tabindex='2'>Insert notes here<div>
<div contenteditable="true" tabindex='3'>Insert notes here<div>

I'm trying to get rid of the "Insert notes here" text when the user tabs to the
. Right now, I'm able to get rid of the text if they click on it with the following jQuery:

function selectText(containerid) {
if(document.getElementById(containerid).innerHTML == "Insert notes here") {
document.getElementById(containerid).innerHTML = "";

Is there a way to achieve the same effect but also when the user uses tab?

Answer Source

sounds like you are looking for the onfocus event


In jquery:

$("#fieldId").focus(function() {
    //your code here 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download