onclick and ondblclick functions being separated

When I double click an element, the flow is being executed with a single click function followed by the double click function and this is not I like to have.

I search for the solution of having two unique functions for either single click and double click and this is it here, I modified the code though:

var timer;
var status=1;
function clickIt(a,b){
if(a==1){//single click
status=1;
timer = setTimeout(function() {
if(status==1)dosomething(b);// this will disable the single click if double click take charge
}, 1000);
}
else {//double click
status=2;
if(timer)clearTimeout(timer);// this will disable the single click if double click take charge
doanother(b);
}
}

The element being trigged to call the the function for either onclick or ondblclick but not both is as such:
<a onclick="clickIt(1,’parameter_1′)" ondblclick="clickIt(2,’parameter_2′)">….</a>

Happy coding!

Posted in 未分類

Setting the first column width of the table different

You can set the first column width of the table element different from the other columns using just css. Code from internet but I like to keep it here for reference:

table tr td { width: 20em; }
table tr td:first-child { width: 10em; }

Anyone interest to use the css code can have this reference as well.

Posted in 未分類

Scroll to the element

This jquery script is very useful when you show some element on a webpage and then you can use this script to scroll right away to the top of this element. You can trigger this with a button or embed the code in your script. This is from internet and you can search for it but I will put it right here for my own reference and for any others who will find it useful:

$(‘html, body’).animate({
scrollTop: $(“#element_to_Scroll_To").offset().top
}, 2000);

Posted in 未分類