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?
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?
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();
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.
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..
In Jquery you can also try by indexOf()
$('*').filter(function() {
return $(this).css('width').indexOf('calc');
}).css("display","none");