I am struggling to make this script working on Wordpress. On Fiddle it works well https://jsfiddle.net/xqxk2qdg/2/ Any idea why could I have this problem? It is properly enqueued and loaded on page.
var array = [];
var array1 = $('#input_8_3').val().split(',');
$("#input_8_3").val(array.join());
(function($){
$('div.thumbn').click(function() {
var text = $(this).attr("id").replace('img-act-','');
var oldtext = $('#input_8_3').val();
if ($(this).hasClass('chosen-img'))
{
$('#input_8_3').val(text+oldtext);
var index = array.indexOf(text);
if (index !== -1)
{
array.splice(index, 1);
}
array1.push(text);
$(this).removeClass('chosen-img');
}
else
{
array.push(text);
var index = array1.indexOf(text);
if (index !== -1)
{
array1.splice(index, 1);
}
$(this).addClass('chosen-img');
}
$("#input_8_3").val(array.join());
$("#input_8_4").val(array1.join());
console.log(array1);
});
})(jQuery);
delete_attachment.js?ver=4.7:2 Uncaught TypeError: $ is not a function(…)(anonymous function) @ delete_attachment.js?ver=4.7:2But still have no idea why.