Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Difference between sibling and children

Tags:

html

jquery

I am trying to understand the following code from this post, and I cannot find out why We use Children vs Siblings. I can understand Children can be following nested tag, but what is level for Siblings?

$('input:checkbox').on('change', function() {
    if ($(this).prop('checked') === true) {
        $(this).parent('div').siblings('.flex-column').children('h2.addMsg').fadeIn("fast").fadeOut(5000);
    } else {
        $(this).parent('div').siblings('.flex-column').children('h2.removeMsg').fadeIn("fast").fadeOut(5000);
    }
});
like image 855
localhost Avatar asked Jun 13 '17 13:06

localhost


People also ask

What is the difference between child and sibling?

A person with no siblings is an only child. While some circumstances can cause siblings to be raised separately (such as foster care) most societies have siblings grow up together. This causes the development of strong emotional bonds, with siblinghood considered a unique type of relationship unto itself.

Is a child a sibling?

Answer. A sibling is a brother or a sister. The plural is siblings, and it can refer to brothers, sisters, or a combination of both. Siblings can be any age; they are not necessarily children.

What is it called when you have a child with a sibling?

nephew. noun. a son of your brother or sister, or a son of your husband's or wife's brother or sister. Their daughter is called your niece.

Is it better to have an only child or siblings?

There is a myth that an only child is often more selfish than someone who has siblings. People believe that they're spoiled and lonely. But the truth is: Children being their first and foremost priority, parents usually try new & innovative activities, thus spending quality time with her.

What is the difference between being an only child and siblings?

The first difference between being only child and being raised among siblings is in terms of getting and sharing stuffs, toys, etc. Obviously, being an only child means that your parents have only you to spend their money and do not have to share with anybody,...

What is the difference between parent to child and sibling transfers?

In its simplest form, parent to child (and grandparent to grandchild) transfers are excluded from reassessment, but sibling to sibling transfers are subject to reassessment when it comes to property taxes. An exclusion occurs when an assessor does not reassess a property because the property is eligible to be excluded if the owner files a claim.

What does it mean to have a younger sibling?

The arrival of a younger sibling means going back to the intense demands of a newborn. Obviously, there will be common denominators between all of your children, no matter what the age difference.

How does the absence of siblings affect a child's development?

Because the child will be an absence of a playmate, the child may grow up as a selfish person unless they learn the idea from school or their peers. In addition, loneliness could cause the child to become depressed or emotionally disturbed. In contrast to a child who has siblings, they are raised among their sister or brother.


3 Answers

Just like in real life with real families, siblings are elements with the same parent element.

So if we have

<div id=1>
  <div id=2>
  <div id=3>
  <div id=4>
</div>

The elements with IDs 2, 3, and 4 are all siblings of each other, and are children of element with ID 1.

like image 92
Matt Ball Avatar answered Sep 30 '22 05:09

Matt Ball


Sibling is not just above same level it is also about same parent. Sibling is like your brother/sister in law (same parent), you are not a sibling to your classmate.

When you click the checkbox, you are children of div

use parent('div') allowed you to target this parent,

use .siblings('.flex-column') will target all sibling of your parent with class .flex-column, then for each of those sibling go to their children find h2 with class addMsg or removeMsg.

For each do fadIn/fadeOut.

$('input:checkbox').on('change', function() {
  if ($(this).prop('checked') === true) {
    $(this).parent().siblings('.flex-column').children('h2.addMsg').fadeIn("fast").fadeOut(1000);
  } else {
    $(this).parent().siblings('.flex-column').children('h2.removeMsg').fadeIn("fast").fadeOut(1000);
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="flex-column">
  <input type="checkbox" />
  <h2 class="addMsg">addMsg 1</h2>
  <h2 class="removeMsg">removeMsg 1</h2>
</div>
<div class="flex-column">
  <input type="checkbox" />
  <h2 class="addMsg">addMsg 2</h2>
  <h2 class="removeMsg">removeMsg 2</h2>
</div>
<span class="flex-column">
  <input type="checkbox" />
  <h2 class="addMsg">addMsg 3</h2>
  <h2 class="removeMsg">removeMsg 3</h2>
</span>
like image 45
Dalin Huang Avatar answered Sep 30 '22 04:09

Dalin Huang


Parent, siblings, children are the relations between the nodes(tags as in case of html)

Siblings: All the nodes which share the same parent are siblings

Children: All the nodes which the current node point to as parent are the Children nodes

e.g.

<html>
   <head></head>
   <body></body>
</html>
  • In the following example "html" is the parent node to the tags "head" and and "body".
  • "head" and "body" tags are siblings to each other.
  • "head" and "body" tags are children when related with the tag "html".
like image 35
Sudeep Padalkar Avatar answered Sep 30 '22 04:09

Sudeep Padalkar