I have this script:
$('.bx').each(function () {
$(this).mouseover(function () {
$(this).css("background-color", "blue");
if (this.id == $('.tester').attr("id")) {
$('div.tester').css("display", "inline-block");
}
});
$(this).mouseout(function () {
$(this).css("background-color", "white");
$('.tester').css("display", "none");
});
});
What I want to do is this: when I hover over some of these input fields, a hidden div should appear. On mouseout, it should hide back.
The thing works, but when i hover over input id="3", the div with id="3" should appear, not all of them sharing the same class name. Same goes with id="4" for both the input and the div. I don`t want to hardcode the ids in there because my inputs and divs are dynamically generated.
That being said, is there any way to achieve this taks?
Any help is appreciated!
Thank you in advance
JSFiddle here: https://jsfiddle.net/pkb3q6kq/19/
You can use
hover
:Changes in HTML:
Javascript:
Demo: https://jsfiddle.net/tusharj/pkb3q6kq/21/
Id
must be unique on the pageeach
loop, you can bind event using classname$(this)
inside event handler is the element on which event occuredhover
as combination ofmouseenter
andmouseout