Hello I have this code :

<div id="user"></div>

And actually this div is defined by the id and it is a checkbox. Do you know how can I get the result of the checkbox ?

I try this :

var users = $('#user');

But when I try this :

alert(users);

I get this :

[object Object]

Could you help me please ?

3 Answers

1
Towan On

By simply only fetching the div with jQuery, you only get the div-object. In order to fetch the checkbox-value you need to call the .val()-method;

var users = $('#user').val();

1
Raj On

Why don't you give some id to your checkbox component and then retrieve it ? by var users = $('#user').val();

0
Community On

Div doesn't hold value so use data- attribute instead like this

var user = $("#user").attr('data-id')
console.log(user)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<div id="user" data-id="abc"> Some text</div>