I'm trying to achive this thing in wordpress wiget admin panel : http://jsfiddle.net/George02/mkuxcwf5/1/
The problem is that the jQuery seems to not work .
public function form( $instance ) { ?>
<?php
wp_register_script('customscript', get_template_directory_uri() . '/widgets/custom_widget/widget.js', array('jquery'), null, true);
wp_enqueue_script('customscript');
?>
<div id="wrapper">
<ul id="category-list">
</ul>
<div id="add-category">
<select id="categories">
<option>Option 1</option>
<option>Option 2</option>
</select>
<div id="btn-add">Add category</div>
</div>
</div>
<?php }
widget.js contains the code from the fiddle. If I View Source
of the page It's seems that the script is there, in the head section, and if I open up the console I can see the log from document ready function . I think the problem is that wordpress doesn't allow me to add items into DOM, because when I inspect the $list element I can see that he has a <li>
inside it.I'm right or it's something else?
<div id="">
with<div class="">
seems that the script is working, but has a inexplicable problem. When I do$('.category-list').append(newCategoryHTML);
a new jQuery object is created, so when I log $('.category-list') I can see in the console 2<ul>
tags. What about this ?