Doubt in quiz-9

what is the jquery equivalent to the following parentelem.appendchild(child one) parentelem.appendchild(childtwo) parentelem.appendchild(child three) please explain this.

1 Like

Hi @shwethashwetha6275 sure child see below here the explanation:-
In jQuery, you can achieve the same result as your provided code using the .append() function. This function allows you to add one or more elements as children to a selected parent element.

Assuming your HTML structure is something like this:

<div id="parentElem"></div>

And you have three child elements you want to append:

<div class="child">Child One</div>
<div class="child">Child Two</div>
<div class="child">Child Three</div>

The jQuery equivalent code would be:

// Appending Child One
$("#parentElem").append("<div class='child'>Child One</div>");

// Appending Child Two
$("#parentElem").append("<div class='child'>Child Two</div>");

// Appending Child Three
$("#parentElem").append("<div class='child'>Child Three</div>");

Explanation:

  1. $("#parentElem") selects the parent element with the ID “parentElem” using its ID selector.
  2. .append() is used to add the specified content (in this case, the HTML strings for the child elements) to the selected parent element.

The provided HTML strings <div class='child'>Child One</div> create new div elements with the class “child” and the corresponding text content. These newly created div elements are then added as children to the selected parent element.

Please note that in modern web development, directly manipulating the DOM like this is less common due to performance and maintainability concerns. Libraries like jQuery were popular in the past for simplifying DOM manipulation.
Hope you understand if you have further more doubts don’t hesitate to ask us !!

1 Like

Ok got it. Thank you.

2 Likes