Getting a css property with jquery

1

Would I have to check a css property with jquery or pure js?

  

Note: Using is (': visible') is not feasible for what I need.

Example:

var display = $('.test').get('display').val()
        if(display == 'block')
        {
            alert('block');
        }
    
asked by anonymous 30.01.2018 / 12:17

2 answers

2

Yes, you can use css to read the computed properties of an object, eg: $('#id').css('background-color');

Reference: link

console.log($('#div1').css('display'));
console.log($('#div2').css('display'));
console.log($('.divClass').css('border'));
#div1 {
  display: inline;
  background-color: red;
  width: 50px;
  height: 50px
}

#div2 {
  display: inline-block;
  background-color: blue;
  width: 50px;
  height: 50px;
}

.divClass {
   border: solid 1px #000
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='div1' class='divClass'>
<div id='div2' class='divClass'>
    
30.01.2018 / 12:23
2
var display = document.querySelector('.sua_classe').style.display;
if(display == 'block')
{
    alert('block');
}
    
30.01.2018 / 12:20