Reputation: 1699
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>
Upvotes: 1
Views: 2681
Reputation: 148110
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'
});
});
Upvotes: 1
Reputation: 4690
Collectively there are two problems in the code,
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'
}
);
});
Upvotes: 1
Reputation: 145398
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.
Upvotes: 4