Edit: both if else statements executing. - I have a table with buttons in it. On page load, if the label of the button is 'Hello', I want to change it to something else. I have if-else statement but all the time, both if else statements are being executed. I do not what is wrong here.
$(document).ready( function() {
if($('button').val() == "Hello" ) {
alert("Hello I am in if");
$(this).removeClass('btn-danger');
$(this).addClass('btn-primary');
$(this).text('ifif');
}
else {
alert("Hello I am in else");
$(this).removeClass('btn-primary');
$('button').addClass('btn-danger');
$('button').text('elseelse');
}
});
Everytime, the label of the button changes to elseelse even when the initial label of button is 'Hello'. First it goes inside if and changes the label to ifif and then goes inside else too.It works fine if I put it in a click event function. But on page load it does not work correctly.
Your responses will be appreciated.
Thanks