I am failing to highlight my div when input tag is focused. Note:Both input tag and my target div's are not in same div.Please see code
<div><input type="text"/></div>
<div>this should change color when input is focused</div>
I am failing to highlight my div when input tag is focused. Note:Both input tag and my target div's are not in same div.Please see code
<div><input type="text"/></div>
<div>this should change color when input is focused</div>
Like this? This uses jQuery
to change css
to the div
$('#someInput').on("focus", function(){
$("#someDiv").css("color", "red")
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div><input id="someInput" type="text" /></div>
<div id="someDiv">this should change color when input is focused</div>
You are trying to select a sibling of the parent ... uncle/aunt ;)
The bad news are: CSS can't do it
However good ol' JS will do the trick
const trigger = document.getElementById("trigger");
const target = document.getElementById("target");
trigger.addEventListener("focusin", function() {
target.classList.add("triggered");
});
trigger.addEventListener("focusout", function() {
target.classList.remove("triggered");
});
.triggered {
color: red;
}
<div>
<input id="trigger" type="text" />
</div>
<div id="target">this should change color when input is focused</div>