-2

Is it possible autofocus on div by css ?

<div class="form-group" style="margin-left:10px">
    <label for="organizationContainer" class="nmc-label">@Res.GroupStrings.CreateNewGroupOrganization</label>
    <div id="organizationContainer" class="form-control nmc-select" style="width:100%!important;border:0px!important;box-shadow:none!important" autofocus></div>
</div>
Carl Binalla
  • 5,393
  • 5
  • 27
  • 46
  • 1
    what does `@Res.GroupStrings.CreateNewGroupOrganization` have to do with the question? – Jaromanda X Jan 29 '20 at 08:54
  • In pure css I doubt it. There seem to be an [autofocus](https://www.w3schools.com/tags/att_input_autofocus.asp) html attribute, however – Pepper Jan 29 '20 at 08:56
  • This question has an [answer](https://stackoverflow.com/questions/3656467/is-it-possible-to-focus-on-a-div-using-javascript-focus-function) already – Sameer Jan 29 '20 at 08:56
  • Does this answer your question? [Is it possible to focus on a
    using JavaScript focus() function?](https://stackoverflow.com/questions/3656467/is-it-possible-to-focus-on-a-div-using-javascript-focus-function)
    – MarkusEgle Jan 29 '20 at 09:50

1 Answers1

0

You can do this easily with Jquery put the following tag in your head section

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"
</script>

Jquery

<script>
  $('#YourDivID').focus();
</script>

Or On button click

<script>

   $('#somebutton').click(function(){
        $('#YourDivID').focus();
   });

</script>