Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    dynamic set onclick attribute for IE

    Hi

    I know it's a common problem, but found solutions didn't help me at all. So, I have a code fragment, which works fine for firefox but doesn't work at all in IE. I'm trying to set onclick attribute on span element (make a 'dynamic' link for ajax usage):

    span = document.createElement("span");
    span.id = "gameRowRemove" + id;
    span.setAttribute("className","link");
    span.setAttribute("onclick",removeGame(this));
    span.appendChild(document.createTextNode("remove"));

    addEventListener gives 'method not supported by this object' error.

    Thanks in advance,
    Michal

    PS. Is there any tool to debug scripts in IE? something like javascript console in firefox? Errors reported by IE are not cleared until browser is restarted, confusing line numbers, sometimes no error at all and script doesn't work...

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    span.setAttribute("onclick","removeGame(this)");

  • #3
    New Coder
    Join Date
    May 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    already tried that, gives no error, but nothing happens after click (in IE of course)

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    use an anonymous. And use DOM 0 syntax in case of class.

    span.className="link";
    span.onclick=function(){removeGame(this)}
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by Kor
    use an anonymous. And use DOM 0 syntax in case of class.
    ...and events. It's a known bug that events added using setAttribute in IE will register in the attr dom, but won't actually work.

    (I know Kor used DOM 0 in the example, but I just thought it needed a specific mention.)

  • #6
    New to the CF scene
    Join Date
    May 2006
    Location
    Port Elizabeth, South Africa
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Kor's code is best, but missing semi-colons. Use...

    Code:
    span.onclick= function() { removeGame(this); };
    Both semi-colons are necessary!

  • #7
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Quote Originally Posted by charlie.
    Kor's code is best, but missing semi-colons. Use...

    Both semi-colons are necessary!
    No they aren't. It should still work without them.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #8
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Quote Originally Posted by charlie.
    Kor's code is best, but missing semi-colons. Use...

    Code:
    span.onclick= function() { removeGame(this); };
    Both semi-colons are necessary!
    None of them are required. Semicolons mark the end of the statement. The same do the } bracket, so that both ;} and }; are redundant
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #9
    New Coder
    Join Date
    May 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    that solved the problem, thanks guys!


  •  

    Posting Permissions

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