Vahid Akbari
Vahid Akbari

Reputation: 189

How to check if a string contains a given string using jQuery

I Use this Code to check a char is contain in string if true checked checkbox but it always return true.why??

//it is mvc project and after execution it become like this:if ($("123:contains(1)"))
if ($("@Model.VillageAR.IncomeLocation.ToString():contains(1)")) 
{
    $('#IncomeLocation1').attr('checked', true);
}

Upvotes: 0

Views: 122

Answers (1)

adeneo
adeneo

Reputation: 318182

I'm guessing you're really just looking for indexOf

if ( "@Model.VillageAR.IncomeLocation.ToString()".indexOf('1') != -1 ) {
    $('#IncomeLocation1').prop('checked', true);
}

Upvotes: 2

Related Questions