When clicking on a certain element, I want another element's background to become, say, red for x seconds before coming back to its original colour, all of this without using UI jQuery, only jQuery. Is it possible ?
To add the background color, we use css() method. The css() method in JQuery is used to change style property of the selected element. The css() in JQuery can be used in different ways. The css() method can be used to check the present value of the property for the selected element.
JavaScript Code:$("div"). on( "click", "button", function( event ) { $(event. delegateTarget ). css( "background-color", "green"); });
JavaScript Code:add("textarea"). css( "background", "red" ); });
If you really need it your way, then do the following: $("#textboxid"). css({"background-color": "color"}); Replace #textboxid with the desired selector, and color with the desired color.
var $el = $("#my-element"),
x = 5000,
originalColor = $el.css("background");
$el.css("background", "red");
setTimeout(function(){
$el.css("background", originalColor);
}, x);
$("#element1_ID").on('click', function() { // click on first element
var bg = $("element2_ID").css('background'); // store original background
$("element2_ID").css('background', 'red'); //change second element background
setTimeout(function() {
$("element2_ID").css('background', bg); // change it back after ...
}, 1000); // waiting one second
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With