Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery to select div inside div inside form

I have this code:

$(document).ready(function() {
  $form.find()

});
#second {
  font-size: 20px;
  color: green;
  background: white;
  text-align: center;
}
<form>
  <div class="first" style="width: 301px; margin:5px 0 0 10px;">
    <div id="second" style="font-size:18px; position: absolute; top: 8px; left: 5px; width: 300px; height: 42px;">Hello</div>
  </div>
</form>

I want to select the div with id="second", in order to change the background to red. Is there any solution to do that using find().

The most important thing for me is to select that div using it's id. jsFiddle

like image 895
ReshaD Avatar asked Dec 06 '25 10:12

ReshaD


2 Answers

$(document).ready(function() {
    $("form").find( "div#second" ).addClass('red');
});

CSS

.red{
   background-color: red;
}
$(document).ready(function() {
    $("form div").find( "div" ).css( 'background-color', 'black');
});
like image 30
D Mishra Avatar answered Dec 07 '25 22:12

D Mishra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!