Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

A more forgiving click area

Posted on 2011-09-23
5
Medium Priority
?
270 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:Tom Knowlton
  • 4
5 Comments
 
LVL 61

Accepted Solution

by:
HainKurt earned 2000 total points
ID: 36588308
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
 
LVL 61

Expert Comment

by:HainKurt
ID: 36588343
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
 
LVL 61

Expert Comment

by:HainKurt
ID: 36588356
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
 
LVL 61

Expert Comment

by:HainKurt
ID: 36588881
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
 
LVL 5

Author Closing Comment

by:Tom Knowlton
ID: 36590569
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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question