JaggsWaggert
JaggsWaggert

Reputation: 171

Making a DIV clickable

I was instructed to wrap an anchor tag around a DIV to make the following PHP clickable. My instincts is that this is a bad idea because it's not valid and bad for SEO, so we can dismiss that idea all together - no need to generate back and forth on that advice. So what would the proper way to make everything in the "box-wrap" DIV point to a link?

<div class="box-wrap">
    <div class="box">
        <header>            
            <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
            <?php echo get_the_term_list( $post->ID, 'categories', '<h3 class="entry-by">' . __('Posted In: ', 'okay'), ', ', '</h3>' ); ?>
        </header>
    </div><!-- box -->
</div><!-- box wrap -->

Upvotes: 0

Views: 1090

Answers (2)

Eric
Eric

Reputation: 97575

As of HTML5, you can legally wrap it in an <a>. In your example, just replace the outer div with an a tag.

<a class="box-wrap" href="...">
    <div class="box">
        <!-- ... -->
    </div>
</a>

Upvotes: 3

Mateusz Rogulski
Mateusz Rogulski

Reputation: 7445

If you want to make your div "clickable" you should use javascript:

$("#clickableDivId").click(function() {
    window.location = "your url";
});

You can also add css style cursor: pointer; to your div looks like anchor.

Upvotes: 0

Related Questions