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…
JavaScript Programming
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…
Add a custom right-click function to a web application. Also can be used to implemen a custom menu opened on right-click: <script language=”javascript” type=”text/javascript”> document.oncontextmenu…
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 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); }, “*…
A very useful snippet code to strip html tags using Javascript: var strippedString = string.replace(/(]+)>)/ig,””); Read entire article and commentshere
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=”…
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…
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”…
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 <!– DOCTYPE –> <html> <head> <title>jQuery – preview button in new tab(window), target blank</title> <script src=”http://code.jquery.com/jquery-latest.js”></script>…