Javascript simple clock

Create a simple function that get the client time (hours:minutes:seconds) and prints it in the div: <script type=”text/javascript”> function getTime() { var currentDate = new…

Get duplicate id’s in DOM using jQuery

Get duplicate id’s in DOM using jQuery // Warning Duplicate IDs $(‘[id]’).each(function(){ var ids = $(‘[id=”‘+this.id+'”]’); if(ids.length > 1 && ids[0] == this) console.warn(‘Multiple IDs…

Create a new rule for jquery.validator plugin

Create a new simple rule for jquery.validator plugin by doing something like this: jQuery.validator.addMethod(“greaterThanZero”, function(value, element) { return this.optional(element) || (parseFloat(value) > 0); }, “*…

Javascript strip tags

A very useful snippet code to strip html tags using Javascript: var strippedString = string.replace(/(]+)>)/ig,””); Read entire article and commentshere

Set and get cookie with Javascript

Javascript function to set cookie: function setCookie(c_name, value, exdays) { var exdate=new Date(); exdate.setDate(exdate.getDate() + exdays); var c_value=escape(value) + ((exdays==null) ? “” : “; expires=”…

Bookmark Script using jQuery

Here is a bookmark script using jQuery: <script language=”javascript” type=”text/javascript”> $(document).ready(function(){ $(“a.jQueryBookmark”).click(function(e){ e.preventDefault(); // this will prevent the anchor tag from going the user off…

Javascript – get Url

Get Url or Url parts using Javascript: window.location.href – get entire url window.location.protocol – get protocol: “http” / “https” window.location.host – get hostname, e.g: “www.g31zone.com”…

Loading JavaScript Asynchronously

Sample of loading javascript asyncronously: <script id=”myscript” type=”text/javascript”> (function() { var myscript = document.createElement(‘script’); myscript.type = ‘text/javascript’; myscript.src = (‘http://example.org/myscript.js’); var s = document.getElementById(‘myscript’); s.parentNode.insertBefore(myscript,…

jQuery – preview button in new tab(window), target blank

jQuery – preview button in new tab(window), target blank <!– DOCTYPE –> <html> <head> <title>jQuery – preview button in new tab(window), target blank</title> <script src=”http://code.jquery.com/jquery-latest.js”></script>…