user6280452
user6280452

Reputation:

Element is hidden not working with css property

I want to check if an element is hidden but the code below is not working properly.

if ( $(element).css('display') = 'none' ){
// element is hidden
}

Upvotes: 2

Views: 46

Answers (2)

rrk
rrk

Reputation: 15846

The code is not working because you are using = you need to use ==.

$(element).css('display') = 'none' will cause error because you are trying to do an assignment operation.

More elegant solution.

if (!$(element).is(':visible')){
    // element is hidden
}

Upvotes: 1

Bhawna Malhotra
Bhawna Malhotra

Reputation: 490

hey in your code you have to put ==

if( $(element).css('display') == 'none' ){

}

Also you can use

$("#idElement").is(":visible") 

Upvotes: 1

Related Questions