If you focus on div, you can’t focus on input to type something.
Solution according to the comment tipo o usuario clica na div busca ai exibe uma borda e um background
, it was said, click on the search div and not in algum elemento da div busca
In this case the solution is, like the other examples, to apply a style to 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>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div class="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. Complete solution because by 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>
<div class="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 div that contains an input with data entry makes this input unfeasible (you will only be able to type 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>
<div class="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>
You want to apply a style to
div
when theinput
get the focus?– Woss
Welcome to a tour starting with this post https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079
– user60252
yes, type the user clicks on the div
busca
ai displays an edge and a background, the examples below some work more have not reached the point I need– goio