SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    301
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to invoke a function ?

    I have a javascript function. I want to call this function when a div content changes .

    however there is no onload() for div.

    How do I invoke the function then ?

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,712
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by windowsxp View Post
    I have a javascript function. I want to call this function when a div content changes .

    however there is no onload() for div.

    How do I invoke the function then ?
    You obtain a reference to the div, and then assign a function to the onchange event of that div.

    For example:

    HTML Code:
    <div id="kittens">
    ...
    </div>
    Code javascript:
    function handleKittenChange() {
        alert('A kitten has changed - how cwute! *squee*');
    }
     
    var kittens = document.getElementById('kittens');
    kittens.onchange = handleKittenChange;
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •