Category Archives: JavaScript

Remove value from input with jQuery

This jQuery code removes the value of a input text type when the user clicks on the input. $(document).ready(function(){ $('input:text').each(function() { var label = $(this).val(); $(this).focus(function() { if($(this).val() == label) { $(this).val(''); } }); $(this).blur(function() { if($(this).val() == '') { $(this).val(label); } }); }); });

Posted in JavaScript | 1 Comment

getElementsByClassName function

Since there doesn’t exist something like a getElementByClassName function, I just tried the js prototype library which has a getElementsByClassName function. You can download it here. Include it in the head like this: <head> <script type="text/javascript" src="prototype.js"></script> </head> Then use it like this: var test = document.getElementsByClassName("test"); the variable test will be an array.

Posted in JavaScript | Leave a comment