MarMan29 MarMan29 - 10 months ago 50
jQuery Question

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.



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