If you focus on the div, you will not be able to focus on the input to type something.
Solution according to comment tipo o usuario clica na div busca ai exibe uma borda e um background
, it was said, click on div search and not on algum elemento da div busca
In this case the solution is, like the other examples, to apply a style to the div simulating focus
$(document).ready(function(){
$(".busca").click(function(e){
$(this).addClass("selected");
e.stopPropagation();
});
$(document).click(function(){
$(".selected").removeClass("selected");
});
});
.selected{
box-shadow: 0 0 5px rgba(0, 0, 238, 1);
padding: 3px 0px 3px 3px;
margin: 5px 1px 3px 0px;
border: 5px solid rgba(255, 255, 10, 10);
background-color: green !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script><divclass="busca" id="onFocus">
<input type="text" name="" class="txt txt_busca" placeholder="faça sua pesquisa"/>
<input type="submit" name="" class="bt bt_busca" value="OK"/>
<p>Faço parte da div</p>
</div>
Other solutions
Example 2
<div class="busca" onclick="this.style.cssText = 'border: 2px solid #96BED9;'">
<input type="text" name="" class="txt txt_busca" placeholder="faça sua pesquisa"/>
<input type="submit" name="" class="bt bt_busca" value="OK"/>
</div>
Example 3
<div class="busca" onclick="this.style.cssText = 'box-shadow: 0 0 5px rgba(0, 0, 238, 1);padding: 3px 0px 3px 3px;margin: 5px 1px 3px 0px;border: 5px solid rgba(255, 255, 10, 10);'">
<input type="text" name="" class="txt txt_busca" placeholder="faça sua pesquisa"/>
<input type="submit" name="" class="bt bt_busca" value="OK"/>
</div>
style Object
You can edit the CSS to apply the desired effect
Example 4 - use of Jquery. Solution complete because clicking outside the div the style is removed
$(document).ready(function(){
$(".busca").click(function(e){
$(this).addClass("selected");
e.stopPropagation();
document.getElementById('onFocus').style.backgroundColor = "red";
});
$(document).click(function(){
$(".selected").removeClass("selected");
document.getElementById('onFocus').style.backgroundColor = "";
});
});
.selected{
box-shadow: 0 0 5px rgba(0, 0, 238, 1);
padding: 3px 0px 3px 3px;
margin: 5px 1px 3px 0px;
border: 5px solid rgba(255, 255, 10, 10);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script><divclass="busca" id="onFocus">
<input type="text" name="" class="txt txt_busca" placeholder="faça sua pesquisa"/>
<input type="submit" name="" class="bt bt_busca" value="OK"/>
</div>
The idea of applying focus to the div that contains an input with data entry makes this input unfeasible (you will only be able to type it if you keep the mouse pointer clicked on it).
See the example below
document.getElementById('onFocus').onclick = function () {
document.getElementById('onFocus').focus();
};
div:focus {
box-shadow: 0 0 5px rgba(0, 0, 238, 1);
padding: 3px 0px 3px 3px;
margin: 5px 1px 3px 0px;
border: 5px solid rgba(255, 255, 10, 10);
}
<div class="busca" tabindex="-1" id="onFocus">
<input type="text" name="" class="txt txt_busca" placeholder="faça sua pesquisa"/>
<input type="submit" name="" class="bt bt_busca" value="OK"/>
</div>
Example 5 - With background defined in CSS also works
$(document).ready(function(){
$(".busca").click(function(e){
$(this).addClass("selected");
e.stopPropagation();
});
$(document).click(function(){
$(".selected").removeClass("selected");
});
});
.selected{
box-shadow: 0 0 5px rgba(0, 0, 238, 1);
padding: 3px 0px 3px 3px;
margin: 5px 1px 3px 0px;
border: 5px solid rgba(255, 255, 10, 10);
background-color: green !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script><divclass="busca" id="onFocus">
<input type="text" name="" class="txt txt_busca" placeholder="faça sua pesquisa"/>
<input type="submit" name="" class="bt bt_busca" value="OK"/>
</div>