Home > Blockchain >  check the total of class of this container then set a condition
check the total of class of this container then set a condition

Time:03-29

I'm new to jquery I would like to ask, how I can declare a condition, by checking the total of a class of the container. because I have several of these classnames but it will be removed based on my set condition, so i am wondering if I have this total of classes on this container, then the style of my container will be changed like this.

if this div.container class has a total of 3 classes of .className then set a .attr('style', 'max-width: 400px !important').

<div >
<div >
<div >
<div >

is this possible? or anyways to have this achievable? please enlighten me. Thank you

CodePudding user response:

Try this,

<script>
$(document).ready(function(){
var count = $('.container .className').length;
if(count==3){
$('.container').attr('style', 'max-width: 500px !important');

}
 
});
</script>
  • Related