make entire div a link?

Brad Bansner
Brad Bansner used Ask the Experts™
on
Can I make a click anywhere inside the boundaries of a DIV a link? Thank you!
<script language="javascript" type="text/javascript">
	$(function(){
		$('#enclosingbox').click(function(){
			window.location.href='my page.htm';
		});
	});
</script>

<div id="enclosingbox">
(a whole bunch of HTML code)
</div>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
leakim971Multitechnician
Top Expert 2014

Commented:
should be the case here...
Brad BansnerWeb Developer

Author

Commented:
OK, not working though:

http://www.lifespanfitness.com/products_home_treadmills.asp

I want to be able to click the text:


Ready to use in minutes. No assembly required. Folds to 11" thin to store under a bed or in a closet. Ideal for occasional light walking.

And that links as well?
<script language="javascript" type="text/javascript">
	$(function(){
		$('#TR100_treadmill').click(function(){
			window.location.href='TR100_treadmill.asp';
		});
	});
</script>


	<div id="TR100_treadmill">
		<div><img src="art/px_trans.gif" width="1" height="12" border="0" alt="" /></div>
		<h5>$699</h5>
		<div><img src="art/px_trans.gif" width="1" height="6" border="0" alt="" /></div>
		<p>Free Shipping or<br />
			Concierge Service</p>
		<div><img src="art/px_trans.gif" width="120" height="1" border="0" alt="" /></div>
	</div>

Open in new window

Multitechnician
Top Expert 2014
Commented:
ok, currently your div is only the price AND IT WORK FINE, check the picture attached
Clipboard03.jpg
Brad BansnerWeb Developer

Author

Commented:
Ah, you are correct. I didn't have it enclosing the text the way I thought. Thanks for taking a look.
leakim971Multitechnician
Top Expert 2014

Commented:
if you add a class to your text :

<p class="class_TR100_treadmill">Ready to use in minutes. No assembly required. Folds to 11" thin to store under a bed or in a closet. Ideal for occasional light walking.</p>

Open in new window


you may use (don't miss the DOT selector before class) :
		$('#TR100_treadmill,.class_TR100_treadmill').click(function(){
			window.location.href='TR100_treadmill.asp';
		});

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial