-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
  • 5,487
  • 11
  • 75
  • 157

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
  • 331
  • 2
  • 8
  • 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
  • 15
  • 2
-1

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

Scott
  • 161
  • 2
  • 17
-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
  • 370
  • 2
  • 16