Skip to content

$.parent()

Arthur Guiot edited this page Jul 25, 2017 · 1 revision

How it works

This function is pretty useful when you're dealing with relative elements because it will make you able to select the parent of an element. Like the .parentNode property from JavaScript.

But we push the concept forward by making you able to select the parent of the parent or the parent of the parent of the parent, etc... You see the concept.

For that, you only need to give how far you want to go.

Parent level
Only the parent 0
Parent of the parent 1
Parent of the parent of the parent 2
... ...

How to use it?

This function will take 2 arguments:

  • element - the child
  • n (optional) - The level. By default n = 0

Example

HTML:

<div class="container">
	<div class="foo">
		<div class="bar"></div>
	</div>
</div>

JS:

$.parent($.s(".bar")) // == $.s(".foo")
$.parent($.s(".bar"), 1) // == $.s(".container")

⚠️ Questions?

Don't hesitate to ask your questions ⁉️ in the issue part 😁

Clone this wiki locally