Reputation: 39018
When my button is clicked I change the color of the text,
after this copy changes text I would like to preform another action.
I wrote the following, but am not able to get a console or alert to work: http://codepen.io/leongaban/pen/IltKJ
$('#my_button').unbind('click').bind('click', function () {
$(this).css('background', '#666666');
$('#my_button').css('color', '#f58733');
if ($('#my_button').css('color') == '#f58733') {
alert('my_button has the color orange');
}
});
I tried the CSS I found from Tamas's answer here.
Any thoughts on why the alert doesn't get hit?
Upvotes: 1
Views: 164
Reputation: 3985
Try this instead:
$('#my_button').unbind('click').bind('click', function () {
$(this).addClass('clicked');
if ($('#my_button').is('.clicked')) { //or use $('#my_button').hasClass('clicked')
alert('my_button has the color orange');
}
});
Upvotes: 3
Reputation: 12305
I update your code....tested in Chrome:
$('#my_button').unbind('click').bind('click', function () {
$(this).css('background', '#666666');
$('#my_button').css('color', '#f58733');
var color = $('#my_button').css('color');
alert(color);
if(color == 'rgb(245, 135, 51)'){
alert('Hi');
}
});
Check Here: http://codepen.io/anon/pen/Dilux
Upvotes: 1