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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts

    None of jQuery UI functions work when called inside of a JS object?

    Hi,

    I am using objects in JS and I am trying to add draggable() into a DIV that works when I move the function out of the object context.

    Example:
    Code:
    function obj_xxx() {
     this.init = function() {
      $(function() { $("#test").draggable();
     }
    }
    
    testobj = new obj_xxx();
    testobj.init();
    That does not work. However, if I do this:

    Code:
    testobj = new obj_xxx();
    testobj.init();
    $(function() { $("#test").draggable();
    Then it will work... because the draggable() function is not within the object.

    I need this to work within the object, because I will have several DIVs associated with objects and I need them to have draggable() in specific cases.

    Help?
    PHP 5 & MySQL 5 (Y)

  • #2
    Regular Coder
    Join Date
    Feb 2009
    Location
    Wheeling, IL
    Posts
    358
    Thanks
    5
    Thanked 62 Times in 60 Posts
    Seems to work fine like this:

    Code:
    <script type="text/javascript">
    function obj_xxx() {
    	this.init = function() {
    		$("#test").draggable();
    	}
    }
    $(document).ready(function() {
    	testobj = new obj_xxx();
    	testobj.init();
    })
    </script>
    All in all, it seems you have one too many unnamed functions, plus you don't seem to be closing all parentheses in your version.
    The way to success is to assume that there are no impossible things. After all, if you think something is impossible, you will not even try to do it.

    How to ask smart questions?

  • #3
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Oh thanks. It works now... I just removed the function part of it...
    PHP 5 & MySQL 5 (Y)

  • #4
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Damn I have a new problem...

    Code:
    $("#test").resizable({resize: function (event, ui) { ... }});
    I am calling that inside the object, but it will not work, because again, there is a function that I use as a callback for onresize event. How would I solve this? I can't just drop the word function...
    PHP 5 & MySQL 5 (Y)


  •  

    Posting Permissions

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