0

I am trying to find find out whats the jQuery equivalent of

style.display.indexOf('none') > -1)

I tried

if(jQuery('#container').css(display).index(none) > -1)

But i am not sure if its right, can anyone give me a hand

Thanks

13
  • What exactly are you trying to achieve? And why you have none without quotes in the second string? Commented Jul 9, 2013 at 6:44
  • 8am no sleep T_T just learning how to code Commented Jul 9, 2013 at 6:45
  • Do you want to get '#container' index? Commented Jul 9, 2013 at 6:45
  • 2
    Don't code with no sleep. Also have a look at how .css works: api.jquery.com/css/#css1. Commented Jul 9, 2013 at 6:46
  • I am trying to code this ` if (document.getElementById('_amd').style.display.indexOf('none') > -1) _ab = true;` to jQuery Commented Jul 9, 2013 at 6:46

4 Answers 4

4

Assuming that objective is to determine if the display property is set to none:

jQuery('#container').css("display") === "none"
                           ^^^ Needs to be a string
                                    ^^^ Should be an equality operator
Sign up to request clarification or add additional context in comments.

2 Comments

what does the -1 mean? and which are the other values? 1, 0 ?what do they represent
The number is the position of the first character in the string that matches. If it is -1 there was no match.
2

Try this

if(jQuery('#container').is(':hidden')) {
    // code
}

Comments

1

You can use :visible selector in your case it will be something like this:

$('#container:visible') 

which return true or false.

Comments

1

You are not enclosing the string in ''

if(jQuery('#container').css('display').index('none') > -1)

but is you are looking for whether the element is displayed then use the :visible selector

if(jQuery('#container').is(':visible'))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.