3

I wanted to hide the element which have calc css3:

nav{width: calc(100% - 20px); height: 50%;}

I tried this:

 $('*').filter(function() {
     return $(this).css('width') == 'calc';
 }).css("display","none");

But seems wrong way to do?

demo

Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231
  • Refer following link it may help you http://stackoverflow.com/questions/17820559/hide-image-of-specific-size-by-css – Lachu Mar 07 '14 at 08:52
  • `css` returns the _computed_ styles, you should read and filter the CSS rules which is _very expensive_. – Ram Mar 07 '14 at 09:01

3 Answers3

2

css method returns the computed value of the properties, you should read and filter the initial CSS rules:

var s = document.styleSheets[1], // the second stylesheet (for jsfiddle)
    rules = s.cssRules,
    selector = [],
    l = rules.length;

for ( var i = 0; i < l; i++ ) {
    if ( rules[i].style['width'].indexOf('calc') > -1 ) {
        selector.push( rules[i].selectorText );
    }
}

$( selector.join() ).hide(); 

http://jsfiddle.net/webozine/9EZ3k/

Ram
  • 143,282
  • 16
  • 168
  • 197
0

jQuery doesn't support a filter with the calc() function in CSS. Following is the screenshot of me testing zooming in and see the css property changing of the nav object.

enter image description here

Here's a somewhat ugly hack I've come up with, it does filter your requirement though.

$('*').filter(function() {
     return  $(this).css('width') == $(this).parent().width()-150 + "px";;
 }).css("display","none");

Or, indeed, add a css class and problem solved..

albusshin
  • 3,930
  • 3
  • 29
  • 57
0

In Jquery you can also try by indexOf()

SEE DEMO

$('*').filter(function() {
          return $(this).css('width').indexOf('calc');
 }).css("display","none");
Rituraj ratan
  • 10,260
  • 8
  • 34
  • 55