Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: Target body on Input:focus [duplicate]

Tags:

html

css

Ive been looking around but have had no luck is it possible (with css) to target the body tag on input:focus so for example when someone clicks on the input box i want the body to have background:red, im not sure if this is actually possible.

Thanks in advance.

Connor

like image 922
iConnor Avatar asked Jul 20 '26 07:07

iConnor


2 Answers

This will be possible in the future with the CSS4 parent selector, but for now you would have to use JavaScript.

like image 145
zakangelle Avatar answered Jul 22 '26 22:07

zakangelle


This is not possible with CSS. But it can be easily achieved with javascript / jQuery :)

This is how to do it in jQuery,

$("input[type=text]").focus(function() {
    $("body").css({"background-color" : "red"});
});
like image 29
Sandeep Raju Prabhakar Avatar answered Jul 22 '26 22:07

Sandeep Raju Prabhakar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!