How to get prop is checked or not with text write


var text = $('#thetext').val();
status.text('On input writed text is'+ text +'');

This get the value writed there but from a .prop how get value? Is checked or not? Like checkbox is checked

What prop are you trying to get the value for?

I have an
<input id="checkboxid" type="checkbox"> and I want to write a text for it if is checked write blablabla but if is not checked then write nothing with at message id

var checkbox = $(’#checkboxid’).prop();
$(’#message’).text(’+ checkbox +’)

Here is an example:

<input id="checkbox-id" type="checkbox"> My Checkbox
  <button id="btn">Check Status</button>
<div id="status"></div>
$("#btn").on('click', function() {
  const checked = $("#checkbox-id").prop('checked');
  $("#status").text('My checkox is ' + (checked ? '' : 'not') + ' checked.'); 
1 Like

Here is another version with the event handler on the change event

<input type="checkbox" name="" id="checkbox">
<div id="output"></div>
$('#checkbox').on('change', function() {
  $('#output').text($(this).prop('checked') ? 'checked' : '')
1 Like