Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4120340
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:12:33+00:00 2026-05-20T23:12:33+00:00

I would like to watch a DOM node property but I can’t seem to

  • 0

I would like to watch a DOM node property but I can’t seem to get it to work.

Within my widget, I’ve tried the following.

startup: function() {
  this.inherited(arguments);

  // First try using the dojo 1.6 watch.
  // I'm setting the property of the widget
  // to reference the DOM node's offsetWidth property
  this.width = this.domNode.offsetWidth;
  this.watch("width", function() {
    console.debug('Width changed to ' + this.domNode.offsetWidth )
  })

  // Does this.width contain a reference or a copy of this.domNode.offsetWidth?

  // Second try, the Mozilla watch
  this.domNode.watch("offsetWidth", function() {
    console.debug('Width changed to ' + this.domNode.offsetWidth )
  })
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T23:12:34+00:00Added an answer on May 20, 2026 at 11:12 pm

    I’m would like to watch a DOM node
    property but I can’t seem to get it to
    work.

    You can’t get it to work by adding Mozilla’s watch directly to the DOM node.

    At http://james.padolsey.com/javascript/monitoring-dom-properties/ mention is made of using setInterval, onpropertychange (IE only), and DOMSubtreeModified (there are other such standard DOM modification events like DOMAttrModified, but you’d have to check browser support). The standard DOM modification events only work if the DOM attribute is changed, not the equivalent property (though you can trigger a mutation event from JS by initMutationEvent):

    <input />
    <script>
    window.onload = function () {
      var ct=0;
      document.addEventListener('DOMAttrModified', function () {
          alert('Value modified ' + (++ct) + ' times');
      }, false);
    
      var input = document.getElementsByTagName('input')[0];
    
      input.setAttribute('value', 5); // Triggers the event
      input.value = 15; // Though it sets the value, it doesn't trigger the event
    
    };
    </script>
    

    // First try using the dojo 1.6 watch.
    // I’m setting the property of the
    widget // to reference the DOM
    node’s offsetWidth property
    this.width = this.domNode.offsetWidth;
    this.watch(“width”, function() {
    console.debug(‘Width changed to ‘ + this.domNode.offsetWidth ) })

    You can monitor the setting of the width property here using the Dojo API, but this does not appear to track the DOM node for you (though http://dojotoolkit.org/features/1.6/widget-watch seems to suggest it does). For example, you can do:

    widget.set('width', 100);
    

    and then your watch event above could be modified to dynamically change the DOM width (but not the offsetWidth since that is a read-only property).

    Still, it appears you’re trying to detect automaticoffsetWidth calculation changes, not your own changes. The best solution for you at this point seems to me to be setInterval.

    // Does this.width contain a reference
    or a copy of this.domNode.offsetWidth?

    A copy since this.domNode.offsetWidth is a number and in JavaScript, non-object types will always get copied by value.

    // Second try, the Mozilla watch
    this.domNode.watch(“offsetWidth”,
    function() {
    console.debug(‘Width changed to ‘ + this.domNode.offsetWidth )
    })

    If this were able to work (and it doesn’t), you’d need to use this.offsetWidth inside the function since Mozilla sets the callback this to that of the object being watched.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i've a userControl (watch the screenshot): I would like to know how can i
I would like Pyinotify to watch a templates directory, which has subfolders, but I'm
YouTube has URL's like these: http://www.youtube.com/watch?v=zKqeCtjFGFc When I create a PHP page mine would
I juste watch this effect : alt text http://grab.by/5UBM I would like to reproduce
I have a Youtube like web-page where users upload&watch videos. I would like to
I would like to read the value from the e.Item.DataItem into a string but
I would like to use some jQuery code to: a) Watch for when an
Watch out, learning sql newbie. I would like to create 2 simple tables. products:
I would like to make a Cakefile task to watch some CoffeeScript files just
I would like to be able, via a watch window, immediate window, or something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.