Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Show/Hide Element in jQuery

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Show/Hide Element in jQuery. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

The Saint-Gobain Glassolutions product configurator displays or hides interface panels based on the user's selections. Write a function that generates the exact jQuery command needed to show or hide an HTML element.

Given a CSS selector and a Boolean visibility value, return $(selector).show(); when the element should be visible, or $(selector).hide(); when it should be hidden. The selector must be inserted between $( and ) and preserved exactly.

Formal Specification

Implement jquery_visibility_command(selector, visible).

  • selector is a non-empty string containing a valid CSS selector.
  • visible is a Boolean.
  • Return a string containing the corresponding jQuery command.

Constraints

  • 1 <= len(selector) <= 100
  • selector contains no newline characters
  • visible is always a Boolean
  • Return only the generated command string

Function Signature

def jquery_visibility_command(selector, visible):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output