Hi
Any pointers on assigning a hyperlink to a div layer? Basically I have a square div with a embedded background pic which I want to to clickable.
thanks in advance.
Hi
Any pointers on assigning a hyperlink to a div layer? Basically I have a square div with a embedded background pic which I want to to clickable.
thanks in advance.
Does the image really need to be the background? That seems weird.... you could just put the image IN the div and be done with it.
Just tried this; it works. Note that it does require javascript, though. Don't think there's another way.
<div onClick="document.location='yoururl';"></div>
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
ok, cheers. Maybe best to work round the js and insert the image.
thanks again
Yeah.... if there's no need for the image to be background (like having text over it, etc.), then that would be the best, most compatible option, as well as being easy.
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
document.location?
I think you mean window.location.href.
Anyway... you can't put a DIV inside an A, because A is an inline element while DIV is a block-level element. djr33's solution, while a tad off on the specifics, is the right idea.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
That's the right way to do it but, of course only the link text will be active as a link.HTML Code:<div><a href="whatever.htm">link text</a></div>
If you give the div a set width and height in its style and set the the a tag's style to width:100%;height:100%;display:block; things should work out pretty well, some tweaking of the style may be required to align the link text (if any, a nonbreaking space - - should at least be used) as desired.
If you were to give a concrete example, I could work out the details. The division tag may not be required at all.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
The document.location worked just fine.
If window.location.href is better, by all means use that.
(Why does document.location work, then? 'cause it worked in a couple browsers, I think... didn't fail in any that I tested... can't remember which I used to test, though.)
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
Don't know... I'd never heard of it(Why does document.location work, then? 'cause it worked in a couple browsers, I think... didn't fail in any that I tested... can't remember which I used to test, though.)After some testing, though, it seems that document.location is always exactly the same as window.location. While you should still be using document.location.href, then, I guess there's no harm.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
This is the HTML forum, anything.location is not a solution to this problem.Originally Posted by Twey
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
But your method creates an annoying character filling the div. What if he needs content to be inside the div?
I agree it's better to use a non-JS solution, but since there is no default way to link a div, I think JS is better than faking a filled div, because that would just mean you could put the image in it, not as a background, and there must be some reason he's not doing this in the first place.
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
Bookmarks