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

  • Home
  • SEARCH
  • 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 7445849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:08:25+00:00 2026-05-29T12:08:25+00:00

Is it possible to simply add event listeners to certain elements to detect if

  • 0

Is it possible to simply add event listeners to certain elements to detect if their height or width have been modified? I’d like do this without using something intensive like:

$(window).resize(function() { ... });

Ideally, I’d like to bind to specific elements:

$("#primaryContent p").resize(function() { ... });

It seems like using a resize handler on the window is the only solution, but this feels like overkill. It also doesn’t account for situations where an element’s dimensions are modified programatically.

  • 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-29T12:08:29+00:00Added an answer on May 29, 2026 at 12:08 pm

    Here is a jQuery plugin with watch and unwatch methods that can watch particular properties of an element. It is invoked as a method of a jQuery object. It uses built-in functionality in browsers that return events when the DOM changes, and uses setTimeout() for browsers that do not support these events.

    The general syntax of the watch function is below:

    $("selector here").watch(props, func, interval, id);
    
    • props is a comma-separated string of the properties you wish to
      watch (such as "width,height").
    • func is a callback function, passed the parameters watchData, index, where watchData refers to an object of the form { id: itId, props: [], func: func, vals: [] }, and index is the index of the changed property. this refers to the changed element.
    • interval is the interval, in milliseconds, for setInterval() in browsers that do not support property watching in the DOM.
    • id is an optional id that identifies this watcher, and is used to remove a particular watcher from a jQuery object.

    The general syntax of the unwatch function is below:

    $("selector here").unwatch(id);
    
    • id is an optional id that identifies this watcher to be removed. If id is not specified, all watchers from the object will be removed.

    For those who are curious, the code of the plugin is reproduced below:

    $.fn.watch = function(props, func, interval, id) {
        /// <summary>
        /// Allows you to monitor changes in a specific
        /// CSS property of an element by polling the value.
        /// when the value changes a function is called.
        /// The function called is called in the context
        /// of the selected element (ie. this)
        /// </summary>    
        /// <param name="prop" type="String">CSS Property to watch. If not specified (null) code is called on interval</param>    
        /// <param name="func" type="Function">
        /// Function called when the value has changed.
        /// </param>    
        /// <param name="func" type="Function">
        /// optional id that identifies this watch instance. Use if
        /// if you have multiple properties you're watching.
        /// </param>
        /// <param name="id" type="String">A unique ID that identifies this watch instance on this element</param>  
        /// <returns type="jQuery" /> 
        if (!interval)
            interval = 200;
        if (!id)
            id = "_watcher";
    
        return this.each(function() {
            var _t = this;
            var el = $(this);
            var fnc = function() { __watcher.call(_t, id) };
            var itId = null;
    
            if (typeof (this.onpropertychange) == "object")
                el.bind("propertychange." + id, fnc);
            else if ($.browser.mozilla)
                el.bind("DOMAttrModified." + id, fnc);
            else
                itId = setInterval(fnc, interval);
    
            var data = { id: itId,
                props: props.split(","),
                func: func,
                vals: []
            };
            $.each(data.props, function(i) { data.vals[i] = el.css(data.props[i]); });
            el.data(id, data);
        });
    
        function __watcher(id) {
            var el = $(this);
            var w = el.data(id);
    
            var changed = false;
            var i = 0;
            for (i; i < w.props.length; i++) {
                var newVal = el.css(w.props[i]);
                if (w.vals[i] != newVal) {
                    w.vals[i] = newVal;
                    changed = true;
                    break;
                }
            }
            if (changed && w.func) {
                var _t = this;
                w.func.call(_t, w, i)
            }
        }
    }
    $.fn.unwatch = function(id) {
        this.each(function() {
            var w = $(this).data(id);
            var el = $(this);
            el.removeData();
    
            if (typeof (this.onpropertychange) == "object")
                el.unbind("propertychange." + id, fnc);
            else if ($.browser.mozilla)
                el.unbind("DOMAttrModified." + id, fnc);
            else
                clearInterval(w.id);
        });
        return this;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simply, is it possible to somehow capture the dimensions (specifically, width and height) of
If I have a var t = document.createTextNode(text) parent.appendChild(t); Is it possible to simply
does anybody know if it's possible (or have experience doing so) to simply bundle
I am using an event-based API and want to have a certain event handling
Since VS 2005, I see that it is not possible to simply build a
To phrase my question as simply as possible, is there a way to create
Is it possible to create images with PHP (as opposed to simply linking to
I remember it is possible to stop a website in IIS simply creating a
In InterfaceBuilder, I'm creating the simplest possible UIButton, by simply dragging from the Library
I tried to make any Component draggable by simply adding mouse listeners and using

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.