You can do this by changing the html markup as follows.
Your selector #in:focus + #input1 {will not work because it +will select the next brother.
#in:focus + #input1will select the element #input1that will be next to #inwhich is focused.
Read more about nearby sibling selector
Updated Fiddle
body {
color: red;
}
#in:focus + #input1 {
color: blue;
}
<input id="in">
<div id="input1">input1:</div>
Run codeHide result
CSS sibling, Javascript.
Vanilla JS:
var input = document.getElementById('in'),
div = document.getElementById('input1');
input.addEventListener('focus', function() {
div.classList.add('focused');
}, false);
input.addEventListener('blur', function() {
div.classList.remove('focused');
}, false);
body {
color: red;
}
.focused {
color: blue;
}
<div id="input1">input1:</div>
<input id="in">
Hide result
jQuery
$('#in').on('focus', function() {
$('#input1').addClass('focused');
}).on('blur', function() {
$('#input1').removeClass('focused');
});
body {
color: red;
}
.focused {
color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<div id="input1">input1:</div>
<input id="in">
Hide result