giannisf
giannisf

Reputation: 2599

jquery comparing string with .val(); non expected result

In my page i have multiple buttons (input type=button) with class ="btnDisabled", every button's value is True or False.

why this code returns always false:

 $(document).ready(function () {

             $(".btnDisabled").each(function(f,el) {

                 console.log($(this).val() == "False");


             });


         });

typeof ($(this).val()) returns string

Upvotes: 2

Views: 414

Answers (3)

byJeevan
byJeevan

Reputation: 3838

Taking an example,

 <input type="button" class="btnDisabled" value="True" />
 <input type="button" class="btnDisabled" value="False" />

In JS :

$(document).ready(function () {
  $(".btnDisabled").each(function(f,el) {
        console.log($(this).val() == "False"); 
   });
 });

Here in console we can see "false" for true button and "true" for false button which is correct. Please refer DEMO HERE if still if you not able to resolve this, Paste your complete code in you post.

Upvotes: 0

Ramzan Zafar
Ramzan Zafar

Reputation: 1600

try using $.trim()

$.trim($(this).val())=="False"

can you paste your html?

Upvotes: 2

hsz
hsz

Reputation: 152206

Just try with:

$(this).is(':checked')

Upvotes: 0

Related Questions