0

I have a quick question. How can I put two items in $ syntax? for example,

  $(document).ready(function(){

    $('#loading_gif' && '#logo_img').fadeIn(2000).fadeOut(2000);

I just put '&&' and did not work. there should be a simple way i guess. Thanks!

DocMax
  • 12,094
  • 7
  • 44
  • 44
Jay Lee
  • 23
  • 2
  • 1
    `$("#loading_gif , #logo_img")`. jQuery accepts all CSS Selectors. – ibrahim mahrir Apr 21 '17 at 19:12
  • 1
    Not usually one to recommend W3Schools, but this is a [pretty decent list](https://www.w3schools.com/jquery/jquery_ref_selectors.asp) for reference – mhodges Apr 21 '17 at 19:15
  • 1
    @mhodges I think the only usefull thing on w3schools are those CSS Selectors lists. I use them all the time as reference. – ibrahim mahrir Apr 21 '17 at 19:17
  • 1
    @ibrahimmahrir Although even then, [they still can be wrong](http://stackoverflow.com/questions/35370441/css-selector-clarification-vs) xD – mhodges Apr 21 '17 at 19:20

3 Answers3

3

The correct code would be:

 $(document).ready(function(){
    $('#loading_gif, #logo_img').fadeIn(2000).fadeOut(2000);
 });

jQuery is using a library called SizzleJS which allows you to use basic CSS selectors to find the elements in the DOM.
You can use '#loading_gif, #logo_img' as a selector while writing your CSS to style both of those elements with their respective ids.

Example

Have fun :)

Mihailo
  • 4,736
  • 4
  • 22
  • 30
2
$('#loading_gif, #logo_img').fadeIn(2000).fadeOut(2000);

is the correct way. && is a Javascript logical operator. Read more about them here.

Shaun Sweet
  • 669
  • 5
  • 9
1

Correct syntax for multi select is

 $('#loading_gif,#logo_img').fadeIn(2000).fadeOut(2000);
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307