Your question has become too vague, I’m not sure if the input points to a specific div, whether you will have multiple inputs and multiple Ivs.
Yet the answer would be something like:
You can use the property .style
or . classname`:
style:
window.onload = function() {
var div = document.querySelector("div[class='tooltip.right']");
var input = document.querySelector(".form-control");
input.onclick = function() {
div.style.display = "block";
};
input.onblur = function() {
div.style.display = "none";
};
};
div[class="tooltip.right"] {
display: none;
}
<input class="form-control">
<div class="tooltip.right">Olá mundo</div>
classname:
window.onload = function() {
var hideClass = /(^|\s)hide(\s|$)/;
var div = document.querySelector("div[class*='tooltip.right']");
var input = document.querySelector(".form-control");
input.onclick = function() {
div.className = div.className.replace(hideClass, " ");
};
input.onblur = function() {
div.className += " hide";
};
};
.hide {
display: none;
}
<input class="form-control">
<div class="tooltip.right hide">Olá mundo</div>
Note:
I recommend not using point classes class="tooltip.right"
, the point is a delimiter to identify the classes in the CSS selectors, it would be better something like:
<div class="tooltip.right hide">Olá mundo</div>
Or if you’re using the point as separator and tooltip and right are two different classes, then the correct one to separate in HTML is space, like this:
<div class="tooltip right hide">Olá mundo</div>
I updated the question
– Alexandre Lopes
I think it’s not quite what I’m looking for. It’s something very simple. Too much code for too little.
– Alexandre Lopes
I just want the <div> that has the
class="tooltip.right"
appears when the person clicks on a<input>
withclass="form-control"
.– Alexandre Lopes
The way you did, the
<input>
disappears when clicked. and the<div>
emerges.– Alexandre Lopes
Yes, there are several. All with the same classes.
– Alexandre Lopes
Both the
<div>
's as the<input>
's– Alexandre Lopes
@Alexandrelopes ae complica se tem várias Divs, I don’t even know how is the whole HTML structure, I recommend reading this topic: http://answall.com/help/mcve and trying to improve the question, understand as a constructive criticism.
– Guilherme Nascimento
Gui, it is possible to do without inserting a
class=""
? Onlystyle="display:block"
? :)– Alexandre Lopes
@Alexandrelopes the first example is exactly that, without class. See I used
div.style.display = "block";
anddiv.style.display = "none";
– Guilherme Nascimento
I’ll test it here! D
– Alexandre Lopes
@Alexandrelopes if you can’t send me the HTML structure of the form, and I make the modifications to work in your form.
– Guilherme Nascimento
I’ll send you here!
– Alexandre Lopes
Look at the fiddle: https://jsfiddle.net/sLLdqmqx/
– Alexandre Lopes
I’ll give you the right answer. : D
– Alexandre Lopes
@Alexandrelopes this is just a div and an input, I asked for the form, need know the structure DOM modify the code. I am waiting.
– Guilherme Nascimento