0
I have an input text.
When Clicking on INPUT "category" opens the #result field, simple! When you type more than 1 character open the #result field, simple!
WHAT I WANT: That the two functions work together! I MEAN when you click by "onclick" or when you do a search "onkeyup"
<!-- ONKEYUP -->
$("#categoria").keyup(function(){
var query = $(this).val();
if($("#categoria").val().length > 0){
$("#resultado").show();//
)};
<!-- ONCLICK-->
$("#categoria").click(function(){
$("#resultado").show();//
)};
Even so I edited to facilitate! Please remove this duplicate
– Alh
Alh, but what you want to do is no longer what is done? Both events display the element with id
resultado
, what you meant by "working together"?– Andre
Remove the callback from
keyup
and declare it as a function:function eventoComum(){var query = $(this).val(); $("#resultado").toggle();}
.Then pass the function to the handlerskeyup
andclick
so that the two share the same callback:$("#categoria").keyup(eventoComum);
and$("#categoria").click(eventoComum)
.– Augusto Vasques
If you click musta to div, or the keyup shows the div, because you don’t just do an event using . Focus(), so it would suit both things... the functionality you want is half incoherent...
– hugocsl