I have a parent element with multiple children each which require different changes. There’s an easy solution, but I’m wondering whether chaining is possible and would be more efficient.
A very simple example:
<div id="parent">
<div class="one">One</div>
<div class="two">Two</div>
<div class="three">Three</div>
</div>
----------------------
$('#parent .one').text('Some');
$('#parent .two').text('Thing');
$('#parent .three').text('Else');
Is there a way to do something similar to this?
$('#parent')
.children('.one').text('Some')
.children('.two').text('Thing')
.children('.three').text('Else');
Where each child resets the chain back to the parent. Also, would this be efficient other than making the code easier to read? Remember, this is a very simple example to clarify the question. I’m not referring to this exact code. I really appreciate the help. Thanks.
end() will return the chain to what it was before the last filtering :