Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making div a clickable link

I have a PHP search script that parses results into HTML div elements to make styling the results easier. I have the following code:

<div class='webresult'><div class='title'><a href='{$row['url']}'>{$row['title']}</a></div><div class='url'>{$row['url']}</div><div class='desc'>{$row['description']}</div></div>

I want to make it so when a the whole webresult div is clicked on, it goes to the url of the result.

I hope people can understand what I'm trying to describe.

like image 670
Callum Whyte Avatar asked Dec 04 '22 21:12

Callum Whyte


2 Answers

If you want to make the entire div clickable, try to style the <a> element as a block element and make its size equivalent to the parent <div>, i.e.,

.title a {
  display: block;
  width: 100%;
  height: 100%;
}
like image 168
timdream Avatar answered Dec 07 '22 10:12

timdream


use jQuery:

$('.webresult').click(function() {
   window.location.href = $(this).find('a').attr('href');
});
like image 36
Inoryy Avatar answered Dec 07 '22 09:12

Inoryy