开发者

Help with URL link and list element and jQuery

开发者 https://www.devze.com 2023-03-02 19:28 出处:网络
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).

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:

  1. 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.
  2. 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.
  3. 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.)
0

精彩评论

暂无评论...
验证码 换一张
取 消