ThemeFuse / Unyson

A WordPress framework that facilitates the development of WP themes
http://unyson.io
922 stars 217 forks source link

How to trigger switch option change via jQuery #900

Closed danyj closed 9 years ago

danyj commented 9 years ago

I found a solution for this #899 via multi-picker option data attributes and on change I run small js to set defaults per style, can you please show me the proper way to trigger change on swith-option type ,

I tried

$('MYID').find('input').val($hovereffect).trigger('click');

but is not 100%

ghost commented 9 years ago

Maybe .trigger('change'); ? https://github.com/moldcraft/adaptive-switch/blob/fa91bb97aef4aa979a96815d658004d8f532920c/jquery.adaptive-switch.js#L72

danyj commented 9 years ago

Hm , no , the click triggers the switch on/off but seems like the value is not changing since there is a hidden input in there value inactive http://prntscr.com/8mhk28

value active

http://prntscr.com/8mhk9n

ghost commented 9 years ago

Try .find('input[type="checkbox"]')

danyj commented 9 years ago

Thnx bud that helped , right one is this

    $('ID').find('input[type="checkbox"]').prop('checked', true).trigger('change');

$('ID').find('input[type="checkbox"]').prop('checked', false).trigger('change');