jQuery/JavaScript Practices

Don't put dashes in class names

If you put dashes, then a livequery selector WON'T work

Catch Enter Key in a field and Trigger an action

add an onkeypress event to the field to call a function like the following

function trapEnter(e){ if(e.keyCode == 13){ codeAddress(); e.preventDefault ? e.preventDefault() : e.returnValue = false; } }

Clear a textbox on focus and restore on exit if not changed.

<scripttype="text/javascript">
  $
("#PostBody").focus(function(){
   
if($(this).text()=="Start a new rugby post"){
      $
(this).text("");
     
}
   
});
   $
("#PostBody").blur(function(){
     
if($(this).text()==""){
       $
(this).text("Start a new rugby post");
     
}
   
});
</script>
Posted by Tom at 00:00

Post a comment

Authors