Skip to content

Instantly share code, notes, and snippets.

@usmans
usmans / clear input feilds jquery
Created December 26, 2012 06:55
clear input feilds jquery
// "inputfields" is the id of the div that contains the text fields.
$('div[id=inputfields] input[type=text]').val("");
@usmans
usmans / Three ways to define a class in javascript
Created December 26, 2012 06:48
Three ways to define a class in javascript
3 ways to define a JavaScript class
Introduction
JavaScript is a very flexible object-oriented language when it comes to syntax. In this article you can find three ways of defining and instantiating an object. Even if you have already picked your favorite way of doing it, it helps to know some alternatives in order to read other people's code.
It's important to note that there are no classes in JavaScript. Functions can be used to somewhat simulate classes, but in general JavaScript is a class-less language. Everything is an object. And when it comes to inheritance, objects inherit from objects, not classes from classes as in the "class"-ical languages.
1. Using a function
This is probably one of the most common ways. You define a normal JavaScript function and then create an object by using the new keyword. To define properties and methods for an object created using function(), you use the this keyword, as seen in the following example.
function Apple (type) {
@usmans
usmans / attach handler to all inputs
Last active December 10, 2015 03:38
Changing Form Input Styles on Focus with jQuery
http://buildinternet.com/2009/01/changing-form-input-styles-on-focus-with-jquery/
<form>
<input name="status" id="status" value="Type something here" type="text"/>
<input value="Submit" type="submit"/>
</form>
<style type="text/css">
    *{
        margin:0;
        padding:0;