-1

I have some html like this

<div class="asd">
    <audio src="...">
</div>

<audio src="...">
<audio src="...">
<audio src="...">

Now I need to select all of the audio elements, that don't have a parent, which has a class asd. I tried something like

$('audio').not('.asd');

But it returns all the audio elements.

How can I do it?

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Sartheris Stormhammer
  • 2,534
  • 8
  • 37
  • 81
  • You can do it with jquery (see https://api.jquery.com/parent/). Please show some effort to solve the problem yourself and tell us where you got stuck. – Mike Scotty Dec 23 '16 at 09:38

1 Answers1

3

You can use :not:

$('audio:not(.asd audio)')

Or .not():

$('audio').not('.asd audio')

var $audio = $('audio:not(.asd audio)');

console.log($audio.length);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="asd">
    <audio src="..." />
</div>

<audio src="..." />
<audio src="..." />
<audio src="..." />
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339