A more forgiving click area

http://utenn.dev.campuswebstore.mobi/

If you can get to this page (not sure if it has propagated yet) on the right hand side navigation, as you hover over each item, it highlights that section in gray.

But, to actually select the item, you have to hover over the word itself.  Can jQuery make it so I can hover anywhere inside the box and a mouse click would be the same as clicking on the text link?  This way people can be  a bit more sloppy in selecting the item.  As long as they are in the highlighted area, a click will be the same as clicking on the link.

See attached image for a reference.

 less precise clcik
LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?
 
HainKurtConnect With a Mentor Sr. System AnalystCommented:
add this to your head

this code is for "<li><a   ..."

elements only... if you are ok with this, extend it for other elements too (like class="catnav")
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript" ></script>

<script>
$(document).ready(function() {
  $("#l_handnav li").click(function(){
    var a = $("a:first",$(this));
    window.location.href = a.attr("href");
  });
});
</script>

Open in new window

0
 
HainKurtSr. System AnalystCommented:
but make sure you close <ul> after last <li>

complete sample is:
<html>
<head>
			<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript" ></script>

<script>
$(document).ready(function() {
  $("#l_handnav li").click(function(){
  	var a = $("a:first",$(this));
  	alert(a.attr("href"));
  	window.location.href = a.attr("href");
  	});
  $(".catnav").click(function(){
  	var a = $("a:first",$(this));
  	alert(a.attr("href"));
  	window.location.href = a.attr("href");
  	});
});
</script>
</head>

<body>

<ul id="l_handnav">

<h3 class="sidebar_header">Top Departments</h3>
<li style="background-color: rgb(250, 250, 250); "><a href="https://utenn.campuswebstore.com/Catalog.aspx?CID=003&amp;c=T-Shirts">T-Shirt</a></li>
<li style="background-color: rgb(250, 250, 250); "><a href="https://utenn.campuswebstore.com/Catalog.aspx?CID=013&amp;c=Jerseys">Jerseys</a></li>
<li style="background-color: rgb(250, 250, 250); "><a href="https://utenn.campuswebstore.com/Catalog.aspx?CID=017&amp;c=Sweatshirts">Sweatshirts &amp; Fleece</a></li>
<li style="background-color: rgb(250, 250, 250); "><a href="https://utenn.campuswebstore.com/Catalog.aspx?CID=004&amp;c=Hats">Hats</a></li>
<li style="background-color: rgb(250, 250, 250); "><a href="https://utenn.campuswebstore.com/booksearch.aspx">Textbooks</a></li>

<h3 class="sidebar_header">School Essentials</h3>
<li><a href="https://utenn.campuswebstore.com/booksearch.aspx">Buy Textbooks</a></li>
<li><a href="https://utenn.campuswebstore.com/Catalog.aspx?CID=025&amp;c=General-Books">General Books</a></li>
<li><a href="https://utenn.campuswebstore.com/Catalog.aspx?CID=022&amp;c=Study-Aids">Study Aids</a></li>
<li><a href="https://utenn.campuswebstore.com/Catalog.aspx?CID=163&amp;c=Graduation">Graduation</a></li>

</ul>
<ul>
<h3 class="sidebar_header">Departments</h3>
<div id="ctl00_Catalogs1_Repeater1_ctl00_licat" class="catnav">
<a href="Catalog.aspx?Cid=001&amp;c=MENS" id="ctl00_Catalogs1_Repeater1_ctl00_HyperLink1" class="catnavinnertext">MENS</a></div>

<div id="ctl00_Catalogs1_Repeater1_ctl01_licat" class="catnav">
<a href="Catalog.aspx?Cid=132&amp;c=CLOTHING" id="ctl00_Catalogs1_Repeater1_ctl01_HyperLink1" class="catnavinnertext">CLOTHING</a>
</div>

<div id="ctl00_Catalogs1_Repeater1_ctl02_licat" class="catnav">
	<a href="Catalog.aspx?Cid=139&amp;c=Camex" id="ctl00_Catalogs1_Repeater1_ctl02_HyperLink1" class="catnavinnertext">Camex</a>
</div>

<div id="ctl00_Catalogs1_Repeater1_ctl03_licat" class="catnav">
<a href="Catalog.aspx?Cid=148&amp;c=T-Shirts" id="ctl00_Catalogs1_Repeater1_ctl03_HyperLink1" class="catnavinnertext">T Shirts</a>
</div>

<div id="ctl00_Catalogs1_Repeater1_ctl04_licat" class="catnav">
<a href="Catalog.aspx?Cid=153&amp;c=QuickSilver-TShirts-" id="ctl00_Catalogs1_Repeater1_ctl04_HyperLink1" class="catnavinnertext">QuickSilver TShirts </a>
</div>

<div id="ctl00_Catalogs1_Repeater1_ctl05_licat" class="catnav">
<a href="Catalog.aspx?Cid=167&amp;c=Supplies" id="ctl00_Catalogs1_Repeater1_ctl05_HyperLink1" class="catnavinnertext">Supplies</a>
</div>

<div id="ctl00_Catalogs1_Repeater1_ctl06_licat" class="catnav">
	<a href="Catalog.aspx?Cid=CES&amp;c=Church-Ed-System" id="ctl00_Catalogs1_Repeater1_ctl06_HyperLink1" class="catnavinnertext">Church Ed. System</a>
</div>

<div id="ctl00_Catalogs1_Repeater1_ctl07_licat" class="catnav">
<a href="Catalog.aspx?Cid=129&amp;c=Trade-Books" id="ctl00_Catalogs1_Repeater1_ctl07_HyperLink1" class="catnavinnertext">
Trade Books</a></div>

<div id="ctl00_Catalogs1_Repeater1_ctl08_licat" class="catnav">
<a href="Catalog.aspx?Cid=151&amp;c=Supplies" id="ctl00_Catalogs1_Repeater1_ctl08_HyperLink1" class="catnavinnertext">
Supplies</a></div>

<div id="ctl00_Catalogs1_Repeater1_ctl09_licat" class="catnav">
<a href="Catalog.aspx?Cid=BEST.SELL&amp;c=Best-Sellers" id="ctl00_Catalogs1_Repeater1_ctl09_HyperLink1" class="catnavinnertext">
Best Sellers</a></div>

<div id="ctl00_Catalogs1_Repeater1_ctl10_licat" class="catnav">
<a href="Catalog.aspx?Cid=456&amp;c=Hoodies" id="ctl00_Catalogs1_Repeater1_ctl10_HyperLink1" class="catnavinnertext">
Hoodies</a></div>

<div id="ctl00_Catalogs1_Repeater1_ctl11_licat" class="catnav">
<a href="Catalog.aspx?Cid=SALE.ITEMS&amp;c=Sale-Items" id="ctl00_Catalogs1_Repeater1_ctl11_HyperLink1" class="catnavinnertext">
Sale Items</a></div>

<div id="ctl00_Catalogs1_Repeater1_ctl12_licat" class="catnav">
<a href="Catalog.aspx?Cid=152&amp;c=new-test-catalog" id="ctl00_Catalogs1_Repeater1_ctl12_HyperLink1" class="catnavinnertext">
new test catalog</a></div>

<div id="ctl00_Catalogs1_Repeater1_ctl13_licat" class="catnav">
<a href="Catalog.aspx?Cid=ROLAN&amp;c=Golf-Accessories" id="ctl00_Catalogs1_Repeater1_ctl13_HyperLink1" class="catnavinnertext">
Golf Accessories</a></div>

<div id="ctl00_Catalogs1_Repeater1_ctl14_licat" class="catnav">
<a href="Catalog.aspx?Cid=149&amp;c=Alumni-Apparel" id="ctl00_Catalogs1_Repeater1_ctl14_HyperLink1" class="catnavinnertext">
Alumni Apparel</a></div>

<div id="ctl00_Catalogs1_Repeater1_ctl15_licat" class="catnav">
<a href="Catalog.aspx?Cid=157&amp;c=Tug-2010" id="ctl00_Catalogs1_Repeater1_ctl15_HyperLink1" class="catnavinnertext">
Tug 2010</a></div>
</ul>

</body>
</html>

Open in new window

0
 
HainKurtSr. System AnalystCommented:
also make sure cursor is set to pointer
<script>
$(document).ready(function() {
  $("#l_handnav li").css("cursor", "pointer");
  $("#l_handnav li").click(function(){
  	var a = $("a:first",$(this));
  	window.location.href = a.attr("href");
  	});

  $(".catnav").css("cursor", "pointer");
  $(".catnav").click(function(){
  	var a = $("a:first",$(this));
  	window.location.href = a.attr("href");
  	});
});
</script>

Open in new window

0
 
HainKurtSr. System AnalystCommented:
without jQuery solution:

if you can modify code do this

<li><a href="https://utenn.campuswebstore.com/Catalog.aspx?CID=025&c=General-Books">General Books</a></li>

-->

<li onClick="goToURL('https://utenn.campuswebstore.com/Catalog.aspx?CID=025&c=General-Books'">Buy Textbooks</li>

and add this js

<script>
function goToURL(href){window.location.href = href;}
</script>

and add a style to li

li {cursor:pointer}

same for other div elements... use goToURL(href) function instead of using "<a ...>...</a>"
0
 
Tom KnowltonWeb developerAuthor Commented:
Your first post with the jQuery was enough to get me unstuck.

Well done by the way...I just plugged it into the top of my script and it worked!

Thanks!

Tom
0
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.

All Courses

From novice to tech pro — start learning today.