How to set multiple CSS display property values with jquery

后端 未结 3 652
温柔的废话
温柔的废话 2021-01-25 00:54

Ok, this is driving me a bit batty. I am using the jQuery .css() method to try to set the multiple flexbox display properties needed for a class. Problem is, it only ke

相关标签:
3条回答
  • 2021-01-25 01:34
    $('.department-name').addClass('test1');
    

    css:

    .test1{
       display : -webkit-box;
       display : -webkit-flex;
       display : -moz-box;
       display : -ms-flexbox;
       display : flex;
    }
    

    You can use addClass() method to add test class into your element. in css() method display property must be getting overrides hence the last one is only applying.

    0 讨论(0)
  • 2021-01-25 01:44

    Store it in a variable:

    var displayStyle = [
      'display: -webkit-box',
      'display: -webkit-flex',
      'display: -moz-box',
      'display: -ms-flexbox',
      'display: flex'
    ].join(';');
    
    
    $(document).ready(function() {
      $(".department-name").attr('style', displayStyle);
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <div class='department-name'>TEST</div>

    0 讨论(0)
  • 2021-01-25 01:47

    Nevermind. There is an h4 inside that .departmentname div that I changed the display property for, so problem solved. Thanks for the feedback though.

    0 讨论(0)
提交回复
热议问题