Q:

how to stop a focus() function in javascript after executing once?

I have an input field in html of password type; I created a function that shows the passwords on focus() in the input field. But the problem is I want the function to be executed only one, and next the user can change the input without making the focus() to work every time.
Here is the script: 
There is a test: it shows a prompt to write the a password in it, then the script checks if the password written is equal to the password of the actual user which is in the session, if yes, then the user can see the password he clicked on it, else he gets an alert to tell him he's not allowed to see passwords.
$('input[class=password]').focus(function(){
               this.type = 'password';
               $pwd=prompt('saisir votre mot de passe');
               if($pwd==='{{ search.password }}') {
                      this.type = 'text';
                     // this.blur();
                   this.off("focus");
                   }
                   else
                   {
                       alert("Vous ne pouvez pas voir les mots de passe!");
                       this.blur();
                   }

               }).blur(function(){
               this.type = "password";
           });

A:

this is the dom element, not a jQuery object. So to use off() you need to change:
this.off("focus");

To:
$(this).off("focus");

There is also one() which will only execute event handler once:
$('input[class=password]').one('focus', function(){...

