I want to check whether a div
with a CSS class="x"
has height="auto"
If yes I want (with a jQuery script) the css-class="a"
removed from all elements with the css-class="y"
If not the script does not have to do anything. Thanks
No, We can not use if-else conditions in CSS as CSS doesn't support logics. But we can use some alternatives to if-else which are discussed below: Method 1: In this method, we will use classes in HTML file to achieve this. We will define different class names according to the conditions which we want to apply in CSS.
They're not programming languages, there is no built logic. No if/else, variables, functions, methods, etc. You cannot use if statements in CSS nor can you in HTML. They're not programming languages, there is no built logic.
Get a CSS Property Value Here's the basic syntax: $(selector). css("propertyName"); The following example will retrieve and display the computed value of the CSS background-color property of a <div> element, when it is clicked.
if ($('div.x').css('height') === 'auto') {
$('.y').removeClass('a');
}
$(document).ready(function(){
if ($('div.x').css('height') === 'auto') {
$('.y').removeClass('a');
}
});
You may need to do that within a each() call
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With