1

I have this function but it gives me function statement require name onStop function

<script type="text/javascript">
 jQuery( function($) {
    $('#Hnav, #Nnav').NestedSortable(
            {
                accept: 'sort',
                noNestingClass: "no-children",
                helperclass: 'helper',
                autoScroll: true,
                onChange: function(serialized) {
                onStop : function(){
                    $('#output').html($(this).id);
                },
                    nestingPxSpace : '0'
            }
    );
});
</script>
1
  • 4
    You didn't close the onChange function correctly so there is a parentheses mismatch Commented Jun 28, 2012 at 10:03

3 Answers 3

4

In this context, this refers to the DOM element on which the onStop event happens. A DOM element is not a jQuery object.

jQuery $(this) object doesn't have id property, while the DOM elements do. So, use either:

$('#output').html(this.id);

or:

$('#output').html($(this).attr("id"));

And don't forget to close the bracket in onChange handler function.

Sign up to request clarification or add additional context in comments.

3 Comments

The answer would be better if you explained the why
@FlorianMargaine Can't do it better :)
May I? :-p I'd just add what this is, so the why one works while another doesn't.
1

Collectively there are two problems in the code,

  1. The inner function was not closed properly.
  2. Used id property of element that is not supported by the jQuery selector.

The modified code is,

jQuery( function($) {
    $('#Hnav, #Nnav').NestedSortable(
            {
                accept: 'sort',
                noNestingClass: "no-children",
                helperclass: 'helper',
                autoScroll: true,
                onChange: function(serialized) {
                    //A empty function
                },
                onStop : function(){
                    $('#output').html($(this).attr("id"));
                },
                nestingPxSpace : '0'
            }
    );
});

6 Comments

there is a problem in JS still when I load the page it says jQuery("#" + s).get(0) is undefined
As far as this code is considered there is no problem now this problem is with the NestedSortable javasciprt file you are using in your code. Also check the HTML #Hnav, #Nnav this could be a problems also.
Thanks for your help i fixed it. I have an issue with toggeling can you please help me?
Why not share your problem. If you are not able to toggle things. I need HTML code and JavaScript code also
wait let me create a question
|
1

There was a bracket missing and you use wrong syntax getting id try this,

$('#output').html($(this).id);

should be

$('#output').html(this.id); 

or

$('#output').html($(this).attr(id));

  jQuery(function($) {
    $('#Hnav, #Nnav').NestedSortable({
        accept: 'sort',
        noNestingClass: "no-children",
        helperclass: 'helper',
        autoScroll: true,
        onChange: function(serialized) {
            alert("changed");// Changed to fix
        },               
        onStop: function() {
             $('#output').html(this.id);
        },
        nestingPxSpace: '0'       
    });
});​

9 Comments

no it's not ... bracket is missing right before the onStop parameter
Try again ... onStop won't be inside onChange
God, you don't even understand what this does does, do you?
Please ignore the -2 answer and concentrate on the +2 one and the comments
I have changed the answer check it again @Zoha Ali Khan and all.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.