Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Adding a link to a class

Featured Replies

Hey All,

 

I have a class called basket, within this class I have a background image as I wanted to overlay text, is there any way for me to make that whole div class a link?

 

ie:

<div class="shoppingBasket">

<p class="items">Currently 0 item/s in basket</p>

</div>

 

Can I add a link to the overall div?

 

Wayne

Edited by waynede

  • Author

Can a mod please close the thread I believe that I have sorted it using JS onclick

 

<div class="shoppingBasket" onclick="location.href='http://www.waynedeboer.co.uk/'" style="cursor: pointer;">

<p class="items">Currently 0 item/s in basket</p>

</div>

bear in mind that the "onclick" version is not SEO friendly.

  • Author

bear in mind that the "onclick" version is not SEO friendly.

 

Thankyou, is their an SEO friendly way of doing what is needed?

Wrap the Div in an anchor tag.

<a><div>Stuff</div></a>

 

Give the Div a style of "cursor:pointer". You might need to also remove any text that gains an unwanted underline. "text-decoration:none"

Do it the way explained in the thread link I posted, all you need to do is make the whole thing a link instead of a div, and if you can't style your text using the basket class and need the items class change it from <p> to <span>.

 

 

Link again if you can't be bothered to look up:

http://www.webdesignerforum.co.uk/topic/43287-clickable-div-as-link-plus-rollover/page__p__272531#entry272531

 

EDIT: Daz you don't need the div in the link like you have done it just needs to be is :

 

<a>Currently 0 item/s in basket</a>

Edited by Dizi

  • Author

Okies, thankyou both for the help, I am reading the post at the moment, I missed it 1st time round as you posted straight after I responded with the onclick.

 

Thanks again.

 

EDIT: Daz you don't need the div in the link like you have done it just needs to be is :

 

<a>Currently 0 item/s in basket</a>

 

So the <a> tag combined with a <span> or <p> would do all that a <div> can do?

 

Learn something new everyday.

You can't combine it with a <p> well you can you can have@

 

<p><a>something </a></p>

 

But you can't have

 

<a><p>something</p></a>

 

as link tags are inline unless you tell them through css to be block, but even then the site won't validate as you can't have a block within an inline, only inlines within a block.

You can't combine it with a <p> well you can you can have@

 

<p><a>something </a></p>

 

But you can't have

 

<a><p>something</p></a>

 

as link tags are inline unless you tell them through css to be block, but even then the site won't validate as you can't have a block within an inline, only inlines within a block.

 

 

So the only reason not to do that method is full validation? That's not too bad then.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.