I'm creating a drop-down element with only one option below. I stuck when I need to show/hide this option.
HTML:
<div id="div1">
<i class="fa fa-plus-square" title="Some title" type="button">
<span id="spanId" title="Some other title">Some text</span>
</div>
<i>
-is the image drop-down button.
CSS:
#div1 {
cursor: pointer;
/*styles, which are not related to the issue*/
}
#spanId {
display: none;
/*some other styles*/
}
#spanId :hover {
background: #e7edf4;
}
So, the span is hidden. I can show it, but after that it is remaining visible for ever and I`m not able to hide it.
JS/JQuery:
let visible = false
const toggleButton = $('#div1')
const dropDownBtn = $('#spanId')
const someOtherButton = $('#someId')
toggleButton.click(() => {
dropDownBtn.css("display", "block")
visible = true
})
if(visible == true){
$(document).click(() => {
dropDownBtn.css("display", "none")
visible = false
})
}
dropDownBtn.click(() => {
someOtherButton.click()
})
Also I tried to do it with <select>
, bu did not succeed. Also try show() & hide()
methods of jQuery. I really can`t realize where am I wrong.