show hide don't work with runtime variable


I wanted to show and hide div based on condition in jquery

Below code works and hide all div's having class "countryselection"

Open in new window

But if I am passing variable at runtime and show all div's like below:

Open in new window

but it doesn't work.

Below is the code snippet. Class in variable "selectedValue" is already applied in the div.

Please advise.
var selectedValue = jQuery(this).val();

alert('vcountry: ' + selectedValue);

Open in new window

Dinesh BaliAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

so you mean first alert and second doesn't match right?
var selectedValue = jQuery(this).val();
alert('vcountry1: ' + selectedValue);


alert('vcountry2: ' + selectedValue);

Open in new window

Dinesh BaliAuthor Commented:

Thanks for your reply

Alert I have placed to see values only.

Everything is working expect last line


I can see alert with correct value for variable selectedValue

alert('vcountry2: ' + selectedValue);
Jeffrey Dake Senior Director of TechnologyyCommented:
What is in the variable selectedValue?  I am guessing a string that represents a classname. If so you would need to do $(‘.’ + selectedValue).show();

It would be helpful to understand what is the output of the alert statement.

Hope this helps

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dinesh BaliAuthor Commented:
Many thanks.
Silly mistake from myside.
Thanks again for pointing it out.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.