Alexander Aguas
Alexander Aguas

Reputation: 13

Syntax error, unrecognized expression: [object HTMLDivElement]input:checkbox[name=]:checked

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());
});

Upvotes: 1

Views: 4487

Answers (2)

alex
alex

Reputation: 490303

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);

Upvotes: 0

Sirko
Sirko

Reputation: 74076

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.

Upvotes: 2

Related Questions