View Single Post
Old 02-11-2013, 12:27 AM   PM User | #5
Vytfla
New Coder

 
Join Date: Apr 2012
Posts: 84
Thanks: 4
Thanked 0 Times in 0 Posts
Vytfla is an unknown quantity at this point
Quote:
Originally Posted by LearningCoder View Post
Hey dude,

You need a way to target the <li> but when you click on either an input or textarea. You wouldn't set the :focus psuedo on the <li> but rather on the inputs and textarea. There's only one way I would know how to achieve this.

Are you familiar with jQuery at all?

I just wrote this for you and it's got the exact same functionality.
Code:
$(function(){
    $('input,textarea').focus(function(){
        $(this).closest('li').css("background", "red");
    });
    
    $('input,textarea').focusout(function(){
        $(this).closest('li').css("background", "none");
    });
    
});
Maybe it could be done with just CSS though I am not sure.

I hope this helps you.

Kind regards,

LC.
So I'm not familiar with js/jquery, would this code go at the bottom of my HTML right before the </body> tag?

EDIT: Or do I put it at the bottom within a <script> tag? Because I tried this and it's not working either
Code:
<script type="text/javascript">
        $(function(){
            $('input,textarea').focus(function(){
                $(this).closest('li').css("background", "blue");
            });
            
            $('input,textarea').focusout(function(){
                $(this).closest('li').css("background", "none");
            });
    
        });
    </script>

Last edited by Vytfla; 02-11-2013 at 12:35 AM..
Vytfla is offline   Reply With Quote