How to select between two list to scroll horizontally using the left, right, and spacebar keys?

How to select between two list to scroll horizontally using the left, right, and spacebar keys? The code shows two ul list, listA and listB each wrapped inside a div. For listA, I can scroll horizontally but don't know how to select the listB to scroll horizontally separately from listA.

<HTML>
<HEAD>
<TITLE>Layout Example</TITLE>
<SCRIPT type="text/javascript" src="jquery-ui-1.8.16.custom.min.js"></SCRIPT>
<SCRIPT type="text/javascript" src="jquery-1.6.2.min.js"></SCRIPT>
<script type="text/javascript">
$(document).ready(function()
{
      $("#containerA ul li:first").addClass("highlight");
      $("#containerB ul li:first").addClass("highlight");

                  $(document).keydown(function(e)
                  {                        
                        if(e.which == 37)
                        {      
                              $("#containerA ul li.highlight").removeClass("highlight").prev().addClass("highlight");

                        }else if(e.which == 39 || e.which == 32)  
                        {
                  
                              $("#containerA ul li.highlight").removeClass("highlight").next().addClass("highlight");
                        }
                  });
            
      
});
</script>
<style>
.highlight
{
      background-color: blue;
      color: white;
}
#containerA, #containerB
{
      height: 100px;
      width: 999px;
      background-color: black;
      color: white;
      text-align: center;
      position: relative;
      border: 5px solid blue;
      padding: 5px;
}
ul
{
        list-style-type: none;
      margin: 0px;
      padding: 5px;
      line-height: 2;
      margin-top: 15px;
      margin-left: 20px;
      margin-right: auto;      
}
li
{
      background-color: gray;
      width: 100px;
      float: left;
      margin-right: 4px;
      margin-top: 3px;
}
</style>
</HEAD>
<BODY>
<div id="containerA"> List A
      <ul id="listA">
                  <li>aaaaaaaaa </li>
                  <li>bbbbbbbbb </li>
                  <li>ccccccccc </li>
                  <li>ddddddddd </li>
                  <li>eeeeeeeee </li>
                  <li>fffffffff </li>
                  <li>ggggggggg </li>
                  <li>hhhhhhhhh </li>
                  <li>iiiiiiiii </li>
      </ul>
</div>
<div id="containerB"> List B
      <ul id="listB">
                  <li>aaaaaaaaa </li>
                  <li>bbbbbbbbb </li>
                  <li>ccccccccc </li>
                  <li>ddddddddd </li>
                  <li>eeeeeeeee </li>
                  <li>fffffffff </li>
                  <li>ggggggggg </li>
                  <li>hhhhhhhhh </li>
                  <li>iiiiiiiii </li>
      </ul>
</div>
</BODY>
</HTML>
areyouready344Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NrisimhaCommented:


Change this code:

<script type="text/javascript">
$(document).ready(function()
{
      $("#containerA ul li:first").addClass("highlight");
      $("#containerB ul li:first").addClass("highlight");

                  $(document).keydown(function(e)
                  {                        
                        if(e.which == 37)
                        {      
                              $("#containerA ul li.highlight").removeClass("highlight").prev().addClass("highlight");

                        }else if(e.which == 39 || e.which == 32)  
                        {
                  
                              $("#containerA ul li.highlight").removeClass("highlight").next().addClass("highlight");
                        }
                  });
            
      
});
</script>

Open in new window


into:

<script type="text/javascript">
$(document).ready(function()
{
      $("#containerA ul li:first").addClass("highlight");
      $("#containerB ul li:first").addClass("highlight");

                  $(document).keydown(function(e)
                  {                        
                        if(e.which == 37)
                        {      
                              $("#containerA ul li.highlight").removeClass("highlight").prev().addClass("highlight");

                        }else if(e.which == 39 || e.which == 32)  
                        {
                  
                              $("#containerA ul li.highlight").removeClass("highlight").next().addClass("highlight");
                        }
                  });
  

                  $(document).keydown(function(e)
                  {                        
                        if(e.which == 37)
                        {      
                              $("#containerB ul li.highlight").removeClass("highlight").prev().addClass("highlight");

                        }else if(e.which == 39 || e.which == 32)  
                        {
                  
                              $("#containerB ul li.highlight").removeClass("highlight").next().addClass("highlight");
                        }
                  });
          
      
});
</script>

Open in new window


Nrisimha
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
areyouready344Author Commented:
thanks Nrisimha but how can I get them to scroll independently and switch between the two list? With your solution, the horizontal scrolling of ListA and ListB takes place at the same time.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.