How to undo a change event for accordion controls

$("#accordion").accordion({ change: function (event, ui) { alert('event have to be changed') }, changestart: function (event, ui) { return false; } }); 

Can I cancel a change event?

+7
javascript jquery jquery-ui accordion jquery-ui-accordion
source share
6 answers

I'm not sure about the change, but for other events in jqueryui returning false, the event is canceled.

+3
source share

stopPropagation () is the key to stop jQueryUI from processing, but it must be interrupted before the changestart event. For example, when the title element is actually clicked.

If this is a title / content pair in your accordion:

 <h3 class='noexpand'>This is a dummy header</h3> <div>This is dummy content</div> 

This will then prevent the expansion of the accordion div when the title is clicked:

 $("h3.noexpand").click(function(e) { e.stopPropagation(); }); 

See jquery accordion prevent bubbling / allow default link action .

+3
source share

As Martin said, you can return the lie. See the sample code below.

 ... eventname: function( event, ui ) { // Add your code here ... return false; } 
+2
source share
 event.preventDefault(); event.stopPropagate(); 
+1
source share

Returning false does nothing to cancel the event in jQueryUI, you need to call preventDefault () on the event.

 $("#accordion").accordion({ changestart: function (event, ui) { event.preventDefault(); } }); 

This should work with all event methods, including autocomplete. It’s convenient if you want to include several customizable options in your autocomplete menu, which you want someone to select, but really don’t want to add to the input to which it is attached. :)

0
source share

What worked for me causes:

 function onChange(e, ui) { e.preventDefault(); e.stopPropagation(); } 

Returning false at the end of the function has the same effect as the equivalent of making these two function calls.

0
source share

All Articles