user1701484
user1701484

Reputation: 233

checkbox not showing due to name attribute

If I have a checkbox which has this name attribute below:

name="answerName[True]"

How come when I peform this jquery line below that it does not show the checkbox?

$(this).closest('.option').siblings('.answer').find('input[name=answerName[Yes]]').show();

if the name attribute was this:

name="answerNameTrue"

and the jquery was this:

$(this).closest('.option').siblings('.answer').find('input[name=answerNameYes]').show();

then it does show but how come when I put [] brackets around it that it suddenly doesn't work and not show the check box?

Upvotes: 1

Views: 120

Answers (3)

poudigne
poudigne

Reputation: 1766

Your [yes] are simply conflicting with the selectors' bracket

Jquery will parse :

find('input[name=answerName[Yes]]')

and will keep :

find('input[name=answerName[Yes]');

So at the end you have a [ that jquery don't know what to do with it + an extra ] at the end of your selector.

Try escaping it :

find('input[name=answerName\[Yes\]]')

or

find('input[name="answerName[Yes]"]')

Upvotes: 0

Ram
Ram

Reputation: 144699

You can use quotation marks:

$(this).closest('.option').siblings('.answer').find('input[name="answerName[Yes]"]').show();

Upvotes: 3

Sushanth --
Sushanth --

Reputation: 55750

True is a javascript Keyword.

That might be one of the reasons this gets messed up..

Try to put the attribute in Quotes and then try..

.find('input[name="answerName[Yes]"]')

Upvotes: 0

Related Questions