www.webdeveloper.com
Results 1 to 4 of 4

Thread: What is the usage of <a href="javascript:;" title="PDF">PDF</a>?

  1. #1
    Join Date
    Jul 2010
    Posts
    11

    What is the usage of <a href="javascript:;" title="PDF">PDF</a>?

    I've seen some code like the following.

    Code:
    <a href="javascript:;" title="PDF">PDF</a>
    When I click it if will pop up a div (by changing its style from "display: none;" to "display: block;" through the modification css attributes).

    This look weird to me, as I don't how an empty javascript statement can cause changes to the webpage. Does anybody have any clue how it can happen? Thanks!

  2. #2
    Join Date
    Nov 2010
    Posts
    1,057
    it's just an obsolete way of doing things. A more modern approach would be
    Code:
    <a href="#" onclick="return false" title="PDF">PDF</a>
    or better, to make a <span>, style it how you like and add an onclick later

  3. #3
    Join Date
    Jul 2010
    Posts
    11
    Quote Originally Posted by xelawho View Post
    it's just an obsolete way of doing things. A more modern approach would be
    Code:
    <a href="#" onclick="return false" title="PDF">PDF</a>
    or better, to make a <span>, style it how you like and add an onclick later
    Can you help create a minimal working example (with the complete code) to make a div visible? I don't quite get why empty javascript command can cause changes to the webpage. A working example can help me better understand what is going on. Thanks!

  4. #4
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    227
    There is certainly more code elsewhere that defines the behavior to the <a> tag. Here's a small example:

    Code:
    <style>
        #hiddenDiv { display: none; }
    </style>
    
    <p><a href="javascript:;" id="theButton">Show it!</a></p>
    
    <div id="hiddenDiv">Hello!</div>
    
    <script>
        var button = document.getElementById('theButton');
        button.onclick = function() {
            var div = document.getElementById('hiddenDiv');
            div.style.display = 'block';
        }
    </script>
    Last edited by ReFreezed; 01-01-2013 at 07:15 PM.
    New to web development or in need of a good reference? Check out the Mozilla Developer Network or W3Schools.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles