ssrp
ssrp

Reputation: 1266

How to get an element by its style value in Jquery

I have the following div

<div class="timeline-axis-grid timeline-axis-grid-minor" style="position: absolute; width: 0px; top: 20px; height: 369px; left: 53.3095px;"></div>

and I want to get this div by its 'left: 53.3095px' value and assign to a variable in Jquery

Upvotes: 1

Views: 94

Answers (5)

Stphane
Stphane

Reputation: 3456

The only way is to filter your collection by testing properties that satisfy your need ...

 $('div.timeline-axis-grid-minor').filter(
    function(){
      var $t = $(this);
      return ($t.css('position') == 'absolute'
             // && $t.css(...  // Add conditions to satify your needs
      );
    }
 );

Upvotes: 2

Neel
Neel

Reputation: 11731

if($('div.timeline-axis-grid').css('left') === "53.3095px"){
  ////your code
}

Or

if($('div.timeline-axis-grid').style.left === "53.3095px"){
      ////your code
    }

Upvotes: 1

Jai
Jai

Reputation: 74738

No that is not available to point any selector that way but instead you can use if conditions to check if a particular element has the exact value then do the intended work:

if($('.timeline-axis-grid').css('left') === "53.3095px"){
   // do stuff here
}

Upvotes: 2

Satpal
Satpal

Reputation: 133403

You can use .filter()

Reduce the set of matched elements to those that match the selector or pass the function's test.

$( "div" )
  .filter(function( index ) {
    return $(this).css('left') === "53.3095px";
  })

Upvotes: 2

Milind Anantwar
Milind Anantwar

Reputation: 82241

try this:

$('div.timeline-axis-grid').filter(function() {
  return $(this).css('left') == '53.3095px';
})

Upvotes: 5

Related Questions