| | |
Using <div onclick="""> to call an <a></a> link
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: May 2009
Posts: 10
Reputation:
Solved Threads: 0
Is it possible to do something like this?
Basically it's to try and make the text work with the a:hover text effect I have whilst making the whole layer sensitive to clicks.
i tried this already:
but it's untidy and a bit rubbish is there a better way to do it neatly?
I know i could always call a JS function to do a parent.location thing but i would rather not if possible.
<div id="btn1" onclick="//somehow call page2Link here"><a href="page2.html" id="page2Link">Page 2</a></div> Basically it's to try and make the text work with the a:hover text effect I have whilst making the whole layer sensitive to clicks.
i tried this already:
<a href="page2.html" id="page2Link"><div id="btn1" ><a href="page2.html" id="page2Link">Page 2</a></div></a> but it's untidy and a bit rubbish is there a better way to do it neatly?
I know i could always call a JS function to do a parent.location thing but i would rather not if possible.
Last edited by peter_budo; Jul 4th, 2009 at 6:05 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Hi there, have you tried:
<div id="blah" onclick="window.location = 'Your reference here'> <a href="You can leave this blank">Your text here</a> </div>
$me = new Person();
if (isset($_COOKIE)){
$me->eat($_COOKIE);
} else { $me->starve(); }
if (isset($_COOKIE)){
$me->eat($_COOKIE);
} else { $me->starve(); }
•
•
Join Date: Jul 2009
Posts: 13
Reputation:
Solved Threads: 3
You can leave out the <a> tag then because you can just use the div:hover.
html Syntax (Toggle Plain Text)
<div id="myButton" onclick="window.location = 'http://google.com';">Page 2</div>
Last edited by Bojero; Jul 3rd, 2009 at 7:04 am.
What I end up doing quite a bit, is making the div clickable, but allowing for people without javascript to access the link (such as search spiders).
One way to do this is using jquery --
Which allows for the div to be clickable.
One way to do this is using jquery --
javascript Syntax (Toggle Plain Text)
$(function(){ $('div.link:has(a)').click(function(){ $(this).addClass('linked'); /*Allows for CSS hover and different styles for link clicks.*/ window.location = $(this).nearest('a').attr('href'); /*Go there! Only works with jquery 1.3 (due to the use of nearest. */ }); //End Click }); //End OnReady
Last edited by peter_budo; Jul 8th, 2009 at 7:20 am. Reason: Correcting openning tag please use [code=JavaScript] instead of [code language=JavaScript]
CodeJoust! Design + Development - Proud User of Ubuntu
•
•
Join Date: Jul 2009
Posts: 13
Reputation:
Solved Threads: 3
•
•
•
•
What I end up doing quite a bit, is making the div clickable, but allowing for people without javascript to access the link (such as search spiders).
One way to do this is using jquery --
[code language=javascript]
$(function(){
$('div.link:has(a)').click(function(){
$(this).addClass('linked'); /*Allows for CSS hover and different styles for link clicks.*/
window.location = $(this).nearest('a').attr('href'); /*Go there! Only works with jquery 1.3 (due to the use of nearest. */
}); //End Click
}); //End OnReady
[/code]
Which allows for the div to be clickable.
•
•
•
•
Thanks to all.
Problem now solved.
ps. Give JQuery a rest some of us like to code in an old school manner where all the code is ours rather than being cut & paste monkeys.
Its also sometimes hard to relearn something too...
CodeJoust! Design + Development - Proud User of Ubuntu
![]() |
Similar Threads
- how can I keep "checked" boxes within div to default to "unchecked" if div is"hidden" (JavaScript / DHTML / AJAX)
- Gridview coloumn data to come in Bulleted list (ASP.NET)
- Why server variable "http_referer" is empty first time? (ASP)
- "simple" file parser i am making (Python)
- Firefox Compatibility help with script (JavaScript / DHTML / AJAX)
- Having a bit of trouble figuring out my image upload script (PHP)
- Javascript - Expected J and Expected Object errors (JavaScript / DHTML / AJAX)
- Selectively Printing only Certain Divs (javascript/css question) (JavaScript / DHTML / AJAX)
- google "keyword" question (Search Engine Optimization)
- Changing the default "submit" button. (HTML and CSS)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: user should not enter future date
- Next Thread: Styles for A Web App
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate automatically beta box browser bug calendar captchaformproblem checkbox child close column createrange() css cursor decimal dependent design disablefirebug dom download dropdown editor element embed engine error events explorer ext file form forms google gwt gxt hiddenvalue highlightedword hint html htmlform ie8 iframe images index internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jump libcurl listbox math media microsoft mimic mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php player post problem progressbar regex runtime scroll search security select shopping size software sql text textarea unicode w3c web website window windowofwords windowsxp wysiwyg \n





