Make An Onclick Event Do Something Different Every Other Click?
I have 3 columns in a table, each with some text at the top and an image below it. I have it so that when someone clicks an image from one of the 3 columns, it enlarges the column,
Solution 1:
What you need is a variable that is accessible to all your functions which will tell you what 'mode' your table is in:
var allColumns = true;
function comedy() {
if (allColumns) {
// ... do stuff here ...
allColumns = false;
} else {
// ... do different stuff here ...
allColumns = true;
}
}
Solution 2:
Something like this would be pretty straightforward:
// Put this within the scope of the <a /> below...var whichClick = 1;
// The link<ahref="..."onclick="javascript:doSomething(whichClick++ % 2 == 1)">Click Me</a>// The handlerfunctiondoSomething(isOdd){
// isOdd is true or false, respond accordingly
}
Etc.
EDIT Tweaked to make function arg a boolean
Cheers
Solution 3:
Its simply, See fiddle demo
HTML
<table><tr><td>Column1</td><tdid="click">Column2</td><td>Column3</td></tr></table>
CSS:
td{
border:1px dotted #ccc;
width:50px
}
JQUERY
$(document).ready(function(){
$("#click").toggle(
function(){
$(this).css('width',200).siblings().hide();;
},
function(){
$(this).css('width',50).siblings().show();;
}
);
})
Post a Comment for "Make An Onclick Event Do Something Different Every Other Click?"