Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()?

like image 351
kernal lora Avatar asked Aug 21 '16 04:08

kernal lora


People also ask

What is the use of show ()?

The jQuery show() method is used to show the selected elements. Syntax: $(selector). show();

What does jQuery hide () do?

jQuery hide() Method The hide() method hides the selected elements. Tip: This is similar to the CSS property display:none. Note: Hidden elements will not be displayed at all (no longer affects the layout of the page). Tip: To show hidden elements, look at the show() method.

Which jQuery method is used to make an element appear?

The show() method shows the hidden, selected elements. Note: show() works on elements hidden with jQuery methods and display:none in CSS (but not visibility:hidden).

What is jQuery appear JS?

jquery-appear-originalThis plugin can be used to prevent unnecessary processing for content that is hidden or is outside of the browser viewport. It implements a custom appear/disappear events which are fired when an element became visible/invisible in the browser viewport.


1 Answers

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

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

to show hidden element

$('#element').show()

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 - http://api.jquery.com/show/ appear/disappear - https://plugins.jquery.com/appear/

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.

like image 159
fedesc Avatar answered Sep 21 '22 00:09

fedesc