How can I combine these jQuery statements?

Alfred

I have a jQuery statement like this;

var current = $(this);
current.hide();
current.siblings('.ab').hide();
current.siblings('.cd').hide();

I want to change this into a single statement and I wrote;

$(current,current.siblings('.ab'),current.siblings('.cd')).hide();

But ab is not hiding. How can I combine the 3 hide() statements into one?

Frédéric Hamidi

You can use a multiple selector and addBack():

$(this).siblings(".ab, .cd").addBack().hide();

addBack() will add the original element back into the set, so you can get both the element and its relevant siblings in the same jQuery object.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I combine these jQuery statements?

From Dev

How can I combine these two statements?

From Dev

How can I combine these two if/else statements for different results?

From Dev

How can I combine two If Statements in PHP to block access to a URL?

From Dev

How do I combine these mysql statements

From Dev

How can I combine two select statements into one table with two seperate columns?

From Dev

How to combine Switch statements?

From Dev

How to combine Switch statements?

From Dev

How to Combine IF statements in Excel

From Dev

How can I combine code

From Dev

How can i combine these lines?

From Dev

how can combine the two sqlite statements into one statement?

From Dev

How do I combine two pig statements into one?

From Dev

Perl regex: how do I combine these 2 regex statements?

From Dev

How do i combine multiple select statements in separate columns?

From Dev

How do I combine two $and statements in an $or statement in mongodb?

From Dev

How do I combine these two while statements into one?

From Dev

How can I avoid these case statements?

From Dev

How can I reduce this long list of if statements?

From Dev

How can I call a constructor after statements?

From Dev

How can I refactor a set of ugly if statements?

From Dev

How can I DRY this series of conditional statements?

From Dev

How can I write regex for the following statements?

From Dev

How can I join these two select statements?

From Dev

How can I make this a prepared Statements code?

From Dev

How to combine these two sql statements

From Dev

API design: How can I combine result of two deferred jQuery objects?

From Dev

How can I combine 2 or more jquery functions with elements that do the same thing but with different names

From Dev

How do I combine two JQuery functions?

Related Related

  1. 1

    How can I combine these jQuery statements?

  2. 2

    How can I combine these two statements?

  3. 3

    How can I combine these two if/else statements for different results?

  4. 4

    How can I combine two If Statements in PHP to block access to a URL?

  5. 5

    How do I combine these mysql statements

  6. 6

    How can I combine two select statements into one table with two seperate columns?

  7. 7

    How to combine Switch statements?

  8. 8

    How to combine Switch statements?

  9. 9

    How to Combine IF statements in Excel

  10. 10

    How can I combine code

  11. 11

    How can i combine these lines?

  12. 12

    how can combine the two sqlite statements into one statement?

  13. 13

    How do I combine two pig statements into one?

  14. 14

    Perl regex: how do I combine these 2 regex statements?

  15. 15

    How do i combine multiple select statements in separate columns?

  16. 16

    How do I combine two $and statements in an $or statement in mongodb?

  17. 17

    How do I combine these two while statements into one?

  18. 18

    How can I avoid these case statements?

  19. 19

    How can I reduce this long list of if statements?

  20. 20

    How can I call a constructor after statements?

  21. 21

    How can I refactor a set of ugly if statements?

  22. 22

    How can I DRY this series of conditional statements?

  23. 23

    How can I write regex for the following statements?

  24. 24

    How can I join these two select statements?

  25. 25

    How can I make this a prepared Statements code?

  26. 26

    How to combine these two sql statements

  27. 27

    API design: How can I combine result of two deferred jQuery objects?

  28. 28

    How can I combine 2 or more jquery functions with elements that do the same thing but with different names

  29. 29

    How do I combine two JQuery functions?

HotTag

Archive