MarMan29
MarMan29

Reputation: 729

first-child without certain class

I'm trying to select the first element under id #pid which contains the .pe class but not the .break class. Then obviously get a certain attribute from that element. I have tried different variations the following doesn't seem to work:

$("#pid .pe:not(.break):first-child").attr("data-time");

neither does :

$("#pid .pe:first-child").not(".break").attr("data-time");

Can someone please tell me what's wrong with my logic.

Thanks

Upvotes: 1

Views: 38

Answers (2)

Ziv Weissman
Ziv Weissman

Reputation: 4526

The problem is with the select of the first child.

This should look like this:

alert($("#pid .pe:not(.break)").first().attr("data-time"));

Or as per Jay's suggestion -

$('#pid .pe:not(.break):first').attr('data-time');

Fiddle example

Upvotes: 1

Jay
Jay

Reputation: 75

Try this:

$('#pid .pe:not(.break):first').attr('data-time');

Upvotes: 2

Related Questions