www.webdeveloper.com
Results 1 to 5 of 5

Thread: Handling Events dynamically

  1. #1
    Join Date
    Mar 2008
    Posts
    10

    Question Handling Events dynamically

    Hai,

    I have added an image dynamically to my webpage, i wanna perform a click event on it, i have used the below code,, but it's not working fine.

    var frm=document.getElementById('frm');
    var img=document.createElement('img');
    img.src='cal.gif';
    img.onclick='DoCal()' \\this line is not working fine.
    frm.appendChild('img')

    Thanks,

    Deepakkumar D

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    img.onclick=function() {DoCal();};

  3. #3
    Join Date
    Mar 2008
    Posts
    10
    Thanks Fang, it's working. When we set a value to an attribute we use
    obj.attribute='value' but for events y do v do like this?

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Yes, if you also want IE to be supported.
    The other exceptions are class and style.
    Code:
    obj.className='foobar'; // class
    obj.style.cssText+=';background-color:blue; color:red;';" // style rules. preferably use class instead of this.

  5. #5
    Join Date
    Mar 2008
    Posts
    10
    Thanks

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