Manoj
Manoj

Reputation: 21

Button colour not changing

Problem- Button colour is not changing, I used jquery click function

<button class="red"  id="MyQuotes" href="#" title="">@Aceo.Crm.App.Resources.Shared.Order.Link_MyQuote</button>

For this button i used jquery as

$(document).ready(function(){
    $("#MyQuotes").click(function(){
    $(this).css({background:"red"});
    });
});

But it was not successfull, I tried to do this in this way too-

<button class="red" onclick="D()" id="MyQuotes" href="#" title="">@Aceo.Crm.App.Resources.Shared.Order.Link_MyQuote</button>

I made javascript function here as-

<script language="javascript">
function D()
{
document.body.style.backgroundColor="red";
}
</script>

And yes this time i was again failed. Can you please suggest me some codes?

Upvotes: 0

Views: 91

Answers (4)

chrisbradbury
chrisbradbury

Reputation: 327

You can use $(this).css("background-color","red"); (and target the correct element id)

fiddle

Upvotes: 0

Marcin Buciora
Marcin Buciora

Reputation: 449

You must refer the button (SO #MyQuotes not #MyOrders) in JS:

$(document).ready(function(){
    $("#MyQuotes").click(function(){
    $(this).css({background:"red"});
    });
});

Upvotes: 0

bipen
bipen

Reputation: 36531

your selector's id is "MyQuotes" and not "MyOrders"

try this

$("#MyQuotes").click(function(){
  $(this).css({background:"red"});
});

OR

function D()
{
  $('#MyQuotes').css({background:"red"});
}

Upvotes: 1

Anujith
Anujith

Reputation: 9370

Using jQuery: http://jsfiddle.net/DrWjq/

$(document).ready(function(){
   $("#MyQuotes").click(function(){
    $(this).css({background:"red"});
   });
});

Pure JS: http://jsfiddle.net/wx9tw/

function D(id)
{
 id.style.backgroundColor="red";
}

<button class="red" onclick="D(this)" id="MyQuotes" href="#" title="">@Aceo.Crm.App.Resources.Shared.Order.Link_MyQuote</button>

Upvotes: 2

Related Questions