Leo
Leo

Reputation: 239

change HTML button value color where value is from onclick calling Javascript

I use the simple button as

<input type="button" value="Search" onclick="ajaxsubmit(this.form)" />

where function ajaxsubmit() looks like

function ajaxsubmit(f) {
$('#sendreq').attr("disabled", true);
$('#sendreq').val("Sending Request");

I want to style button onclick value (Sending Request) to change its color to red but the color of the initial button value (search) should not change

Upvotes: 0

Views: 1896

Answers (2)

Jeff
Jeff

Reputation: 12183

JS:

function ajaxsubmit(f) {
  $('#sendreq').attr("disabled", true);
  $('#sendreq').val("Sending Request").addClass("redbutton");
}

CSS (Text Color, use background-color if thats what you want. You can use any styles that should be applied):

.redbutton{
    color:red;
}

Whenever you want to remove the red text, just call .removeClass("redbutton") on your button element.

Upvotes: 3

Mark Pieszak - Trilon.io
Mark Pieszak - Trilon.io

Reputation: 67219

$('#sendreq').css('background', '#FF000');
$('#sendreq').addClass('redBackground');

This could be done in multiple of ways! Pick and choose :)

Upvotes: 1

Related Questions