-1

I have a number of DIVs on the page with class="row". I need a selector for one that had a child div with id="test".

<div class="row">
  <div class="col col-12">
    <div id="test">
      This is a test
    </div>
  </div>
</div>

How do I select that particular row?

div.row div#test 

did not work for me.

I tried accessing it using

$('div.row div#test ').show();

but nothing happened.

Coding Duchess
  • 6,445
  • 20
  • 113
  • 209

4 Answers4

0
$('div.row').has('div#test').show()

With $('div.row') you get the row's divs. The method 'has('div#test')` applies a filter on these elements but still returns the row divs. See jQuery.has()

Here is an example: jsFiddle

Glia
  • 371
  • 2
  • 9
  • 2
    Please explain your answer, provide context, and / or links to documentation of the features that make this work. – nvioli Oct 08 '18 at 16:24
-1

Maybe this works for you?

$('#test').parent().parent()
Richard
  • 27
  • 5
-1

You would only need to specify..... #test

Scott
  • 171
  • 3
  • 23
-1

You can use jQuery .find helper to let it work with one or multiple same ids: $('div.row').find('div#test').show();

Marco Dal Zovo
  • 369
  • 2
  • 17