Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery children selector

I have the following markup:

<div class="form-fields">
  <div class="row">
    <span class="info">Info</span>
  </div>
</div>

Using the children selector how can I select span.info? I have tried doing:

$('.form-fields').children('.row .info')

But this didn't work for me.

EDIT: Thanks for the answers everyone. If I assign the container DIV as follows:

var parentDiv = $('.form-fields')

Then using the var 'parentDiv' what is the best way to select span.info?

like image 227
MAX POWER Avatar asked Dec 12 '22 16:12

MAX POWER


2 Answers

Use find to get non-direct descendants:

$('.form-fields').find('.row .info')
like image 76
lonesomeday Avatar answered Jan 02 '23 00:01

lonesomeday


Why do you need to use .children?

$('.form-fields span.info')
like image 43
SilentGhost Avatar answered Jan 02 '23 01:01

SilentGhost