SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Jul 2004
    Location
    Netherlands
    Posts
    672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do i add a onclick attribute?

    Code:
     // Create link to delete the div and form
            var deleteLink = document.createElement('a');
            deleteLink.innerHTML = 'Delete';
            deleteLink.href = '#';
            deleteLink.onclick = 'test';
    It works all except the onclick? Is there anyway to add this?
    Go visit my site :-D you know you want to ;-)
    www.mech7.net

  2. #2
    SitePoint Guru
    Join Date
    Jul 2004
    Location
    Netherlands
    Posts
    672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm this way works.. looks bit messy though :\

    HTML Code:
    // Create link to delete the div and form
            var deleteLink = document.createElement('a');
            deleteLink.innerHTML = 'Delete';
            deleteLink.href = '#';
            deleteLink.setAttribute('onclick', 'Element.remove(\'' + 'tag' + li.id + '\'); return false;');
    Go visit my site :-D you know you want to ;-)
    www.mech7.net

  3. #3
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    deleteLink.onclick = function() {
    // do what you want in here.
    }



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
  •