Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8342955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:54:58+00:00 2026-06-09T05:54:58+00:00

if( $(div:last).is(:visible) ) { $(p).css(color, red); } why the script don’t work correctly? http://jsfiddle.net/8Rrm2/8/

  • 0
if( $("div:last").is(":visible") ) {
    $("p").css("color", "red");
}

why the script don’t work correctly?

http://jsfiddle.net/8Rrm2/8/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T05:55:00+00:00Added an answer on June 9, 2026 at 5:55 am

    The script only checks if its visible at the time of running. It doesn’t check if it is ever visible. So when the user uses the right arrow key to make it visible, the script has already passed and it remains not-red. You would have to move that logic into your event handler.

    Here is a working fiddle. All I did was cut and paste your logic.

    Now, every time the user presses an arrow key, it updates the button and changes the color appropriately.

    Also, just FYI: KnockoutJS has some amazing tools for model-binding. With almost no scripting, you can have a model and view-model automatically update each other. The arrow key updates your view-model value, which in turn automatically creates changes in your view. It’s really worth looking into, and their tutorials are quite fun.

    Here is an example of your script, modified to work with Knockout, in case you’re curious. In this example, its not a ton less code, but I do think its a little cleaner to read and to handle “exceptional cases”. For example, if you wanted it to be red on values 2, 5, and 7, it just requires changing the one function called iAmRed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any JS/CSS/jQuery magic I can work to identify whether the last visible
jsFiddle is here: http://jsfiddle.net/qBQD4/ It's pretty simple really; I want the right arrow to
var a=$('#start > div:last-child'); var b=$('#start > div.live')[0]; alert(a==b) alert(a==$(b)) It's always false. How
jQuery 1.4: $('#menu li:last:not(.ignore)').addClass('last'); HTML: <div id=menu> <ul> <li>item 1</li> <li>item 2</li> <li class=ignore>item3</li>
I have a form element defined as: <div class=field> <div class=name> <label for=User_LastName> Last
I cannot get this last div to go up properly in my layout and
I'm trying to select the last div with class my_class inside div with id
IMHO the following is the typical 3-column-layout using CSS. Without the surrounding #main-div it
In the following markup, "image 3" would the only visible div if all .image
How would you go about applying a background color with CSS only, while only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.