jquery - How to set input `autofocus` on when it is toggle? -


i have hidden div. when link clicked, div should toggle input field , dropdown select. how make input field autofocus div slides down?

this html hidden div:

<div class="new-category-box">     <div class="form-group">         <input type="text" class="form-control" id="new_category" name="new_category" autofocus>     </div>     <div class="form-group">         <select class="form-control" name="parentcategorylist">             <option>-- parent category --</option>             <option value="">lorem ipsum</option>             <option value="">lorem ipsdffum</option>         </select>        </div>           <div class="form-group">         <button type="submit" class="btn btn-default">add new category</button>     </div>   </div>   

i went through question. div not toggle.

this jquery:

$( "a.add_new_category" ).click(function() {     $( ".new-category-box" ).slidetoggle(function(){             $("#new_category").focus();         });     ); }); 

can tell me wrong code?

you have few errors, have been corrected:

$( "a.add_new_category" ).click(function() {    $( ".new-category-box" ).slidetoggle(function() {      $("#new_category").focus();    });    // ); - stuff need removed!  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>  <div class="new-category-box">    <div class="form-group">      <input type="text" class="form-control" id="new_category" name="new_category" autofocus>    </div>    <div class="form-group">      <select class="form-control" name="parentcategorylist">        <option>-- parent category --</option>        <option value="">lorem ipsum</option>        <option value="">lorem ipsdffum</option>      </select>       </div>          <div class="form-group">      <button type="submit" class="btn btn-default">add new category</button>    </div>    </div>


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -