3

Is there a nicer way in jQuery to do this ?

$(":text").each(function() {
   if (this.style.visibility == "visible") {
      ...
   };
});

3 Answers 3

5

yes:

$(":text:visible").each(function() {
   ...
});

UPDATE Since jQuery this doesn't work anymore: details.

Sign up to request clarification or add additional context in comments.

5 Comments

Note that this is probably what the OP wants, but not the literal translation (since they're using visibility and not display).
@Nick, in that case, $(":text:visible, :text:not(':hidden')".each(.. would work.
None of the options above works for me :( Note that I set the "visibility" like this: $("#myid").attr("style", "visibility: hidden"); What I see is all elements including the hidden ones...
For setting visibility you should use: $("#myid").css("visibility","hidden"). Also note the updated answer..
What is the difference between $("#myid").attr("style", "visibility: hidden") and $("#myid").css("visibility","hidden") ?
0

You're looking for the :visible selector:

$(':text:visible')

Comments

0

For speed use

$(':text').filter(":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.