EliasMP EliasMP - 11 days ago 5
HTML Question

Jquery not working. I can´t figure it out

Coded this function I´m not being able to find why is not working.

I know the JS file is loaded because other functions inside it are working, but those with this format not:

$(function () {
....
});


The idea is to show a modal windows when you click in a specific div (class addWidget), after that Jquery function will count some divs and show them in the modal window (before) for check them if you want.

The code is the next one:

-- JQUERY --

$(function () {
$('.addWidget').on('click', function () {
$('.modal-body').empty();
$('.modal-title').text('Añadir Widget');
$('.box:hidden').each(function () {
$('.modal-body').append('<input type="checkbox" value="' + $(this).attr('name') + '"> ' + $(this).attr('name') + '</input><br />');
});
if ($('.modal-body').children('input').length > 0) {
$('#modal').modal('show');
} else {
$('.modal-title').empty();
$('.modal-body').text('Todos los widgets estan desplegados');
$('#modal').modal('show');
return false;
}
});
});


When I clicked in the div, nothing happens... :(

EDITED:

Trying this approach, at least, is entering in my Jquery´s function:

function addWigdet() {
$('.modal-body').empty();
$('.modal-title').text('Añadir Widget');
$('.box:hidden').each(function () {
$('.modal-body').append('<input type="checkbox" value="' + $(this).attr('name') + '"> ' + $(this).attr('name') + '</input><br />');
});
if ($('.modal-body').children('input').length > 0) {
$('#modal').modal('show');
} else {
$('.modal-title').empty();
$('.modal-body').text('Todos los widgets estan desplegados');
$('#modal').modal('show');
return false;
};
} (jQuery);

onclick="javascript:addWigdet()"


But:

$('#modal').modal('show');


Crash... Something about this element doesn´t support modal('show')...

Answer

Well,

Finally Found it. Just sharing for avoiding this problem if you all have the same issue.

I solved taking another way, probably, not the proper one but fix it.

The problem is related with something about using the master page and loading the specific jquery function inside, so, for fix this specific problem with this specific function (really odd, other functions working out), I decided to load the function in each page which need it...

Hoping it works for you guys.

Comments