jQuery: chaining of multiple child elements
jquery, jquery-selectors
Solution
end() will return the chain to what it was before the last filtering :
$('#parent')
.children('.one').text('Some').end()
.children('.two').text('Thing').end()
.children('.three').text('Else');
Problem
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.