-5

How to change and use this function:

$(function() {
  $("a#toggle").click(function() {
    $("#yellow_div").slideToggle();
    return false;
  });
});

to run when input text get focus?

<input id="toggle" type="text" />
   <div id="yellow_div" style="display:none;">
      <p>Hello</p> 
   </div>

2 Answers2

0

This will run the code when your input gets focused

$(function () {
   $("#toggle").focus(function () {
      $("#yellow_div").slideToggle();
      return false;
   });
})
mhodges
  • 10,938
  • 2
  • 28
  • 46
0
$("#toggle").focus(function() {

or

$("#toggle").on('focus', function() {

Should do the trick, as long as you're talking about your input#toggle

neilsimp1
  • 1,242
  • 1
  • 11
  • 25