Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select an element by it's margin-left

So basically I have some div's and I need to select just the ones that don't have a margin-left set, or it's set to 0px.

Is there any way I can achieve this with jQuery ?

<div class="col col-xs-12"></div>
<div class="col col-xs-12" style="margin-left: 0px;"></div>
<div class="col col-xs-12" style="margin-left: 10px;"></div>
<div class="col col-xs-12" style="margin-left: 20px;"></div>

In this example I should select the first 2 div's because both of them have a margin-left of 0px (the first is not set but it's still 0px);

PS. I prefer not to use a for for this operation.

like image 833
paulinho Avatar asked Apr 18 '26 08:04

paulinho


1 Answers

You could use filter() to achieve this:

$('.col').filter(function() {
    return parseInt($(this).css('margin-left'), 10) == 0;
});

Example fiddle

like image 104
Rory McCrossan Avatar answered Apr 19 '26 21:04

Rory McCrossan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!