I have a snippet in Jquery like below
$(document).ready(function() {
$('button#company').click(function() {
var id = 0;
var div = $(this).parents('div');
var names = div.find('p[data-name*=name'+id+']');
$.each(names, function(key,value) {
console.log(value);
} );
console.log('ok');
});
});
I have the following result in console, as expected
<p class="hidden" data-name="name0_0">
<p class="hidden" data-name="name0_1">
<p class="hidden" data-name="name0_2">
ok
The problem is, when I use console.log(value.val());
.
All script stops and anything happens, any error and even ok is not printed.
When I try to debug and put a breakpoint in console.log(value.val())
the script stops in the line, but anything happens.
I also tried .text()
and .html()
and I have the same problem.
console.log(names)
results in:
Object { 0: <p.hidden>, 1: <p.hidden>, 2: <p.hidden>, 3: <p.hidden>,
4: <p.hidden>, length: 5, prevObject: Object, context:
<button#company>, selector:
"p[data-name*=name0]" }
The HTML is:
<div>
<p class="hidden" data-name="name0_0">James</p>
<p class="hidden" data-name="name0_1">John</p>
<p class="hidden" data-name="name0_2">Carl</p>
<button id="company" class="btn btn-default">Go!</button>
</div>