Can someone tell how to have a button chnage colour on selection. and change back once another link is selected. I have tried using

::selection selector in css (but this is not compatible in ie)

Thanks

Jonathan

Recommended Answers

Have you explored using JavaScript as an option?

document.getElementById("id").style.backgroundColor="value"
Jump to Post

Here is a more complete example that you can play around with:

<html>
<head>
<script type="text/javascript">
 function chgBtn()
 {
   document.getElementById("btn").style.backgroundColor="red";
 }
</script>
</head>
<body>

  <button id="btn" type="button" onclick="chgBtn()">Set background color</button>

</body>
</html>
Jump to Post

All 5 Replies

Have you explored using JavaScript as an option?

document.getElementById("id").style.backgroundColor="value"

Here is a more complete example that you can play around with:

<html>
<head>
<script type="text/javascript">
 function chgBtn()
 {
   document.getElementById("btn").style.backgroundColor="red";
 }
</script>
</head>
<body>

  <button id="btn" type="button" onclick="chgBtn()">Set background color</button>

</body>
</html>

Thanks for your swift reply. This works great but once I click on the button this stays red even if i click on a different link.

I would like the button to change colour on selection but if i was to select a different link or any other part of the page. I would like the button to change to its original colour.

Sorry, missed the part about the color changing back when you click on another link. Hmmm. I need to get back to you on this one.

got this sorted using some java of stack overflow.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.