1

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?

Community
  • 1
  • 1
Leon Gaban
  • 36,509
  • 115
  • 332
  • 529

2 Answers2

3

Try this instead:

Codepen

$('#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');
    }
});
musicnothing
  • 3,977
  • 24
  • 43
  • Thanks! :D I had a problem with loading a page after clicking that button. Well the page would load, but the color wouldn't change, I'd have to click it again to get the color to change. So I figured the page loading interrupted the color change – Leon Gaban Aug 13 '13 at 22:13
1

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

Hackerman
  • 12,139
  • 2
  • 34
  • 45