0

I'm trying to create a widget plugin that uses a jQuery code to show/hide divs in the widget form based on the selected option of a select drop menu.

The jQuery code I'm trying to implement is working fine everywhere else, but in the widgets page it makes the widgets not working (not expandable or dragable).

This is my code on jsfiddle:

http://jsfiddle.net/fj63g/111/

/* update */

The full plugin code can be found here:

http://jsfiddle.net/qNc62/

6
  • Your JS code helps might little in thiscase . when widget are non draggable nor expandable (or another symptom is the page stops loading at a certain widget - and hence no sidbars locations) there are 2 reasons 99% of the cases . A) a PHP syntax error (look at the source and see error message) B) A JS conflict/syntax error (you can easily verify with debug tools in your browser) in the other 1% of the cases wp core file pluggable.php is curropt. reinstall wp. In your specific case i can only guess that you need to change all $ istances to jQuery because in wp it loads in noconflict mode
    – krembo99
    Feb 6, 2014 at 2:38
  • Thanks alot for your help! I don't get any php errors, it's mostly a JS error. And whether I use $ or jQuery it's still not working.
    – Ahmed Saad
    Feb 6, 2014 at 2:57
  • why are you using an OLD jQuery in fiddle ?
    – krembo99
    Feb 6, 2014 at 2:59
  • The latest one, even the one on Google CDN. Anyway, I've uploaded the full plugin code, please give it a try and install it as a plugin.
    – Ahmed Saad
    Feb 6, 2014 at 3:05
  • It's not about fiddle anyway, it's about wordpress, I'm testing on wordpress is 3.8, and the fiddle is just for the showcase.
    – Ahmed Saad
    Feb 6, 2014 at 3:11

1 Answer 1

0

used $ within (function($){ /* code */ })(jQuery);

:D

<script type="text/javascript">
(function($) {
$(document).ready(function(){
  $('#kopko').change(function() {
    $("#" + this.value).show().siblings().hide();
  });
  $("#kopko").change();
});     
})(jQuery);
</script>
5
  • Still no luck. I'll upload my full plugin code so you can try it.
    – Ahmed Saad
    Feb 6, 2014 at 3:00
  • yes, pleace ... :D Feb 6, 2014 at 3:03
  • Done; jsfiddle.net/qNc62. Upload and test.
    – Ahmed Saad
    Feb 6, 2014 at 3:23
  • Did you try my plugin yet?
    – Ahmed Saad
    Feb 6, 2014 at 15:31
  • This only works when at '?widgets-access=on'. But not at '?widgets-access=off' (from the Screen Options)... I guess there's something wrong with jQuery loading.
    – Ahmed Saad
    Sep 4, 2014 at 21:04

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.