I am trying to select a sibling from "this" in jquery

$ (this is + "p") slideDown ("slow") ;.

$ (this) + $ ("p") slideDown ("slow") ;.

$ ("this + p") slideDown ("slow") ;.

does not work.

+3
source share
3 answers

The Next .

$(this).next("p").slideDown("slow")

Make sure the p element is right next to it. Otherwise, you will want to use nextAll.

+1
source

Yes, your syntax is bad. You should use the jQuery Sibling function :

$(this).siblings().find("p").slideDown("slow");

The jQuery API site is awesome for finding things like this, I rely on it almost daily. I will follow him.

+2
source

jQuery, , ? , , , .

next() - dom, .

Use instead. means that only the first level is canceled.

$('body > div').hide();

But it gives the same result.

$('body').children('div').hide();

But,

  • Further
  • $('body + div').hide();

and

  • Previous
  • $('body ~ div').hide();

Doesn't seem to work as expected? But jQuery use it as an example to select CSS ...

Perhaps there is a complicated syntax for this, but I could not figure it out ...

0
source

Source: https://habr.com/ru/post/1749661/


All Articles