kernal lora kernal lora - 1 year ago 309
jQuery Question

jQuery appear() and show() methods difference?

I'm studying for a HTML, CSS, JS exam and found various resources to help me study. In doing a practice quiz, I found this question.

You are creating a page that contains detailed employee information for a company portal. The page uses a jQuery library. The page contains a hidden button named btnEdit that is defined by the following code.

<button id="btnEdit" style="display: none;">Edit</button>

The button is not displayed by default.
The button must be displayed only if the user is logged on.
You need to add code to the document.ready() function to meet the requirements for the button.
Which line of code should you use?

A. $ ('#btnEdit').appear();
B. $ ('#btnEdit').visible = true;
C. $ ('#btnEdit').show();
D. $ ('#btnEdit').Visible();

The quiz telling me that option A is correct.
I haven't use appear() method before.

My question is:

  1. .appear(), Is this function really as a part of jQuery library?
    I could not find .appear() function in jQuery doc. No results in jQuery API

  2. Is that option A is correct? If it is correct can anyone tell me why?
    As of my conscience option C is correct(If I'm wrong correct me).

  3. Can anyone please tell me difference between appear() and show()?
    And when to use appear(), when to use show()?

Answer Source

Show is a function to show a selected element. e.g:

<i id='element' style='display:none;'></i>

to show hidden element


As Jquery says disappear/appear is a custom event you can fire once the element is shown. so it should look something like -

$('#element').appear(function() {
  ... code goes here

For jQuery reference show - appear/disappear -

Edit - i think it's also safe to say that show is packed with options and a 'complete' callback which is fired once the element has finished shown.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download