Home>
When I press the check box multiple times, I want to put characters on the console according to the state of the check box.
On the first click, the console display seems to work fine, but after the second time, the console value is the same as the first time, and it seems that it does not work well.
What kind of code should I write in these cases?
HTML
<input type = "checkbox" name = "selector" data-category = "15" checked>
jQuery
$('# s-option'). click (function () {
// If it is not checked
if ($('input [name = "selector"]'). prop ('checked', false)) {
console.log ('Not checked');
// if unchecked
} else {
console.log ('Checked');
}
});
-
Answer # 1
-
Answer # 2
if ($(' input [name = "selector"] '). prop (' checked ', false)) { ↓↓↓ if ($('input [name = "selector"]'). prop ('checked') == false) {
Related articles
- javascript - about switching the display between desplay: none;and desplay: block;
- javascript - i want to create a switching tab using jquery
- javascript - switching image display vuejs
- javascript - [jquery] i want to change the pop-up display when leaving the page
- javascript - get and display elements from page with jquery ajax
- javascript - i want to change the display by selecting the radio button
- javascript - i want to display a drop-down menu using css and js in html
- javascript - i want to display google map in the view
- i want to paste a link in csv, display it in javascript, and jump to that link
- javascript - i want to display the contents of an associative array and a combination of arrays
- i want to display the value obtained from postgresql with javascript on erb
- javascript - show/hide div element with jquery
- javascript - i want to display the value entered in the created form in slack with incoming webhooks
- javascript - i'm writing a script with jquery, but i can't enclose it in single quotes
- javascript - debugging the prependto method in jquery
- javascript - i want to display the icons at the right end of the same row
- javascript - i can't display the application problem of fizzbuzz well
- javascript - i want to change the display range of the array
- javascript - coexistence of jquery refinement and pagination
- i want to judge the screen width with jquery and javascript
Related questions
- javascript : JS, HTML: How to get data from a form if there are several of them and they have the same class
- javascript : Recursion in a function in jQuery
- javascript : CSS hover and document.querySelector
- javascript : How to implement an additional block for table rows?
- javascript : Ajax -how to store the result into a variable?
- javascript : The problem with the for algorithm [duplicate]
- javascript : How do I send any non-form data using Ajax to mail?
- javascript : How do I stay on the current /switch to the previous tab?
- javascript : I cannot animate correctly and remove an element from a dynamic list
- javascript : Save password in browser when submitting form via JS /jQuery ajax
Is the judgment method below?