javascript void(0) for HTML link

May 27, 2012

To create a HTML link which does nothing when user clicks it,  use  like below


<A HREF="javascript:void(0)">Click here to do nothing</A>

When the user clicks the link, void(0) evaluates to undefined, which has no effect in JavaScript.

References –

https://developer.mozilla.org/en/JavaScript/Guide/Expressions_and_Operators#void

Here is a stackoverflow.com link, which answers why  void(0)  is better than using #  for this requirement

http://stackoverflow.com/questions/134845/href-for-javascript-links-or-javascriptvoid0


Internet Explorer min-width CSS property does not work

July 13, 2011

If the min-width property does not work in Internet Explorer
http://www.w3schools.com/cssref/pr_dim_min-width.asp

check if your html has DOCTYPE setup.

min-width details from MSDN site – http://msdn.microsoft.com/en-us/library/ms530820(v=vs.85).aspx
states that

This property is enabled only under the strict !DOCTYPE.


Difference between Div and Span tag

January 27, 2011

Good article in the link below about this
http://webdesign.about.com/od/htmltags/a/aa011000a.htm

Simple point to keep the difference in your mind is Div tag adds new line , Span tag does not


Convert JSON Object to String javascript

January 26, 2011

you can user browser native function JSON.stringify to do this

var foo = {};
foo.bar = "new property";
foo.baz = 3;

var jsonString = JSON.stringify(foo);

https://developer.mozilla.org/En/Using_JSON_in_Firefox

And IE8 also supports it – http://blogs.msdn.com/b/ie/archive/2008/09/10/native-json-in-ie8.aspx


jQuery Template plugin html in variables

January 25, 2011

If you pass html content in the template variables, you have to use {{html ..}} format to make sure that the html content gets converted into real html elements.

See this Stack overflow post http://stackoverflow.com/questions/4570222/htmlentities-equivalent-in-jquery-template-plugin

And this documentation – http://api.jquery.com/template-tag-html/


Javascript code equivalent to java i18n MessageFormat

January 25, 2011

Here is a Stack overflow post with javascript regex solution for this problem.

http://stackoverflow.com/questions/1353408/messageformat-in-javascript-parameters-in-localized-ui-strings


How to center a div inside a div

January 17, 2011

If you need to center a div within another div, here is the solution from Stack overflow post –
http://stackoverflow.com/questions/114543/how-to-center-div-in-div