Page 1 of 2

How to change the color property of a button

Posted: Sun Dec 09, 2012 9:39 pm
by yaip

I have a button. When the user clicks it, I want to change the color, say from blue to green. How?


How to change the color property of a button

Posted: Mon Dec 10, 2012 3:21 am
by maxkatz

On click run JavaScript. Select the component in the DOM and update its style. You can select the component directly with jQuery or use Tiggzi(id) function: http://docs.tiggzi.com/javascript-api/


How to change the color property of a button

Posted: Mon Dec 10, 2012 7:50 pm
by yaip

Thx. I looked at the example. Still not clear how to change the color.


How to change the color property of a button

Posted: Mon Dec 10, 2012 8:49 pm
by yaip

I have:

Tiggzi('btn').style.bgcolor="#ffffff";

This doesn't work.


How to change the color property of a button

Posted: Mon Dec 10, 2012 8:52 pm
by yaip

** Solved **


How to change the color property of a button

Posted: Mon Dec 10, 2012 8:55 pm
by maxkatz

Great. Can you post the code for other users?


How to change the color property of a button

Posted: Mon Dec 10, 2012 9:30 pm
by yaip

Tiggzi('btn').live('click', function() {
var dotoggle = $(this).attr("dotoggle");
if ( dotoggle == "1" ) {
$(this).css('background', 'green');
$(this).attr("dotoggle","0");
}
else {
$(this).css('background', 'red');
$(this).attr("dotoggle","1");
}
});

this works but the problem is that I have to double-click instead of single-clicking it for the color to change


How to change the color property of a button

Posted: Mon Dec 10, 2012 9:36 pm
by maxkatz

What browser? Same result in a different browser? Try the click event but with something as alert(...).


How to change the color property of a button

Posted: Mon Dec 10, 2012 9:52 pm
by yaip

Chrome on a Mac. I also tried it on FF on a Mac as well as Chrome on PC. Same result. Tells me that something's wrong with my code.


How to change the color property of a button

Posted: Mon Dec 10, 2012 9:53 pm
by yaip

try it yourself