Created
February 21, 2012 08:43
-
-
Save waako/1875199 to your computer and use it in GitHub Desktop.
Get value of last nested li and output in element of same parent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Trying to print title value of :last li.nested.one in the closest div.header --> | |
<ul> | |
<li class="parent"> | |
<div class="header"></div> | |
<ul> | |
<li class="nested one"> | |
<li class="nested one"> | |
<li class="nested one" title="first"> | |
<li class="nested two"> | |
<li class="nested two"> | |
</ul> | |
</li> | |
<li class="parent"> | |
<div class="header"></div> | |
<ul> | |
<li class="nested one"> | |
<li class="nested one"> | |
<li class="nested one" title="second"> | |
<li class="nested two"> | |
<li class="nested two"> | |
</ul> | |
</li> | |
<li class="parent"> | |
<div class="header"></div> | |
<ul> | |
<li class="nested one"> | |
<li class="nested one"> | |
<li class="nested one" title="third"> | |
<li class="nested two"> | |
<li class="nested two"> | |
</ul> | |
</li> | |
<li class="parent"> | |
<div class="header"></div> | |
<ul> | |
<li class="nested one"> | |
<li class="nested one"> | |
<li class="nested one" title="fourth"> | |
<li class="nested two"> | |
<li class="nested two"> | |
</ul> | |
</li> | |
</ul> | |
<script> | |
var title = $('li.nested.one:last', 'li.parent').attr('title'); | |
$('li.nested.one:last', 'li.parent').each(function() { | |
$(this).closest('.header').text(title); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try this mate