SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2008
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SetAttribute and Onclick return false

    Hi! I want to implement:

    <a href=123 onclick="javascript:return false">123</a>

    in DOM,

    I have:

    var link = document.createElement('a');
    link.setAttribute('href', 123);
    link.setAttribute('onclick', 'function() { return false; }');

    but it doesn't work. The reason I want a href and onclick = false is because I want to drag and drop the 123.

    Please help. Thanks

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code JavaScript:
    var link = document.createElement("a");
    link.setAttribute("href", "123"); // Value must be a string.
    link.onclick = function () {return false};
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2008
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!


Bookmarks

Posting Permissions

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