Finding first div id in DOM

Total Post:5

Points:35
JQuery 
 320  View(s)
Ratings:
Rate this:

I want to select first div. How to do this. 

<div style="border: 1px solid black;">

  <p>first paragraph</p>
</div>
<br>
<div style="border: 1px solid black;">
  <p>second paragraph</p>
</div>

please anyone helpme

  1. Post:1

    Points:7
    Re: Finding first div id in DOM

    You can use first function in jquery

    <head>
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        $("div").first().css("background-color", "yellow");
    });
    </script>
    </head>

Answer