Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Jquery If condition True add style visibility:hidden

I’m trying, if an "if" condition is true, to set the style of an element to "visibility:hide;".

I’ve done this:

if (user.privilege = 3) {
        $("#persone").css("visibility:hidden;");
}

But when the If condition runs, in the console i get this error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

"Uncaught TypeError: Cannot read properties of null (reading ‘style’)"

What should i do to solve this?

var html = '<div class= "col-lg-6">'+
           '<label class="mt-15">A chi è riferito l\'evento? </label>' +
                 '<select class="form-control" id="persone" >' +
                    _this.GetOptionPersone() +
                 '</select >' +
           '</div>' ;

>Solution :

You’ve got a couple of syntax issues. Firstly = is for assignment. To compare values you need to use == or ===.

Secondly css() accepts 2 arguments, the rule name and its value, and it shouldn’t have the trailing ;.

if (user.privilege == 3) {
  $("#persone").css('visibility', 'hidden');
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading