How to check whether a checkbox is checked in jQuery?

I need to check the checked property of a checkbox and perform an action based on the checked property using jQuery.

For example, if the age checkbox is checked, then I need to show a textbox to enter age, else hide the textbox.

But the following code returns false by default:

 

if ($('#isAgeSelected').attr('checked')) { $("#txtAge").show(); } else { $("#txtAge").hide(); }

[removed][removed] <input type="checkbox" id="isAgeSelected"/>

Age is selected

In Progress 19-01-2020 Zeeshan 59

Please briefly explain why you feel this question should be reported .

Answers (0)

Leave An Answer

A PHP Error was encountered

Severity: Notice

Message: Undefined index: id

Filename: cache/d97ac842e5cd4223dfc53b2a6eeeeebb4411f7f4.php

Line Number: 59

Backtrace:

File: /home/eruski/public_html/application/cache/d97ac842e5cd4223dfc53b2a6eeeeebb4411f7f4.php
Line: 59
Function: _error_handler

File: /home/eruski/public_html/application/vendor/illuminate/view/Engines/PhpEngine.php
Line: 43
Function: include

File: /home/eruski/public_html/application/vendor/illuminate/view/Engines/CompilerEngine.php
Line: 59
Function: evaluatePath

File: /home/eruski/public_html/application/vendor/illuminate/view/View.php
Line: 142
Function: get

File: /home/eruski/public_html/application/vendor/illuminate/view/View.php
Line: 125
Function: getContents

File: /home/eruski/public_html/application/vendor/illuminate/view/View.php
Line: 90
Function: renderContents

File: /home/eruski/public_html/application/cache/b6ccfc02d41a8c769df5592a1420c116e6348c26.php
Line: 15
Function: render

File: /home/eruski/public_html/application/vendor/illuminate/view/Engines/PhpEngine.php
Line: 43
Function: include

File: /home/eruski/public_html/application/vendor/illuminate/view/Engines/CompilerEngine.php
Line: 59
Function: evaluatePath

File: /home/eruski/public_html/application/vendor/illuminate/view/View.php
Line: 142
Function: get

File: /home/eruski/public_html/application/vendor/illuminate/view/View.php
Line: 125
Function: getContents

File: /home/eruski/public_html/application/vendor/illuminate/view/View.php
Line: 90
Function: renderContents

File: /home/eruski/public_html/application/cache/82ef4d9f910d594a9a48dfe0970db178efe68f19.php
Line: 269
Function: render

File: /home/eruski/public_html/application/vendor/illuminate/view/Engines/PhpEngine.php
Line: 43
Function: include

File: /home/eruski/public_html/application/vendor/illuminate/view/Engines/CompilerEngine.php
Line: 59
Function: evaluatePath

File: /home/eruski/public_html/application/vendor/illuminate/view/View.php
Line: 142
Function: get

File: /home/eruski/public_html/application/vendor/illuminate/view/View.php
Line: 125
Function: getContents

File: /home/eruski/public_html/application/vendor/illuminate/view/View.php
Line: 90
Function: renderContents

File: /home/eruski/public_html/application/controllers/Home.php
Line: 577
Function: render

File: /home/eruski/public_html/index.php
Line: 315
Function: require_once