I have a challenge where I need to update the text within '#foo #three' by using 'this' to access the text of the div#one
The desired output would be:
- cat
- dog
- cat
This is how the HTML looks:
<div id="foo">
<div id="one">cat</div>
<div id="two">dog</div>
<div id="three">mouse</div>
</div>
And this is the JavaScript code snippet:
$("#foo #three").text($(this).parent().children().first().text());
I am looking for a way to make this code dynamic.
You can also find this example on JSFiddle: http://jsfiddle.net/Kodam/s466a31q/