Help with URL link and list element and jQuery
I'm t开发者_运维知识库rying to get a list element to point to a URL.
For some reason, it does not link (because of the id="mylink" inside a href). The jQuery loads up an image map perfectly when I rollover the list item. No worries here. Simply turing to make my a href work...Can some please let me know why the URL is not working?
<script>$(function() {
$('.map').maphilight();
fade: true,
$('#mylink').mouseover(function(e) {
$('#mapbox').mouseover();
}).mouseout(function(e) {
$('#mapbox').mouseout();
}).click(function(e) { e.preventDefault(); });
});</script>
The list item:
<li><a href="mylink/index.html" id="mylink">My Link</a></li><br />
.click(function(e) { e.preventDefault(); });
You are telling it NOT to allow the browser to continue loading the href that the link points to.
I see three potential problems with your code:
- Most importantly, it isn't syntactically valid. Perhaps it's just a copy/paste error, but you have what appears to be an object property (
fade: true,
) as a statement, at which point the JS parser will fail. - Your
click
handler is preventing the default action of the link — following the URL — without attaching any other functionality to it, ensuring that nothing happens when the link is clicked. - Your
<script>
and</script>
tags are on the same line as code. This is generally best avoided. (Historically, some browsers have had issues with this, though it may no longer be an issue.)
精彩评论