I can't seem to see any results on google unless I use jQuery and I'm not so sure if jQuery and javascript plain work together.
Asked
Active
Viewed 1,568 times
0
-
Yes, should be possible. Can include `html` , `css` , `js` tried at Question ? – guest271314 Jan 25 '16 at 00:50
-
1for clarification ... jQuery is a javascript library.that simplifies interacting with the dom ... so it will not conflict with any native script – charlietfl Jan 25 '16 at 01:00
2 Answers
0
Try using data-*
attribute to store color replacement, original background color of button
element or initial
setting; JSON.parse()
, JSON.stringify()
, Array.prototype.reverse()
to toggle data-*
attribute values that set background
of input type="button"
element; onclick
event.
Not certain if requirement is to toggle background color, or reset to original color once ?
<input type="button" value="button" data-colors='["blue", "buttonface"]' onclick="this.style.background = JSON.parse(this.dataset.colors)[0]; this.dataset.colors = JSON.stringify(JSON.parse(this.dataset.colors).reverse());" />

guest271314
- 1
- 15
- 104
- 177
0
jQuery will not conflict with javascript, it is just a js library :) So you can use the selector.css()
of jquery or, in standard js i think it is (element).style.background = color
.
I recommend using jQuery. Here is a SIMPLE jQuery way to do it:
$("#button").click(function(){
$("#tochange").css("background-color", "colorhex");
});
If you want to swap colors you could, for example, add a variable.
var x;
$("#button").click(function(){
if(x==0){
$("#tochange").css("background-color", "colorhex");
x= 1;
}
else{other way round}
});

Heady
- 935
- 3
- 10
- 23