I try to make a form with jquery 1.11.1, but the checkboxes do not work! which is the syntax error?
$(this + "input[name=''] :checked").each(function() {
totalSum += parseInt($(this).val());
});
You probably want to use something like this:
$( this ).find( "input[name='']:checked" ).each(function() {
totalSum += parseInt($(this).val());
});
Using find() you can search for elements, which are descendants of a given element.
Anyway, are you sure you want to search for <input> elements, which have a name attribute set to an empty string? Because that is, what you are currently selecting.
$("input[name='']:checked",this), which is the same as your answer.Just to be different...
var totalSum = $(this)
.find("input[name='']:checked")
.map(function() { return parseInt(this.value, 10); })
.get()
.reduce(function(total, value) { return total + value; }, 0);
thisplus a string as a selector. and remove that space before:checked[object HTMLDivElement]is the syntax error in the selector.thisis a DOM element. What did you expect from concatenating a DOM element with a string?