I am working with an array of names, some of which are repeated. These names are then split in half and displayed as li
.
One thing I am struggling to figure out is how to style the name Joeyc
with text-decoration: line-through;
on all instances of .book
where joeyc
is present. Check out my code snippet below along with a link to a JSFiddle:
<div id="book1" class="book">
<ul class="hardcover_front">
<li></li>
<li></li>
</ul>
<ul class="hardcover_back">
<li></li>
<li></li>
</ul>
<ul class="book_spine">
</ul>
</div>
.
.(similar blocks for book2-book10)
.
<script>
var votenames = ["Joeyc", "JakeP97", "Joeyc", "TheKid", "Joeyc", "TheKid", "Joeyc", "JakeP97", "ExploreMeDora", "Alvaro"];
var ballots = ["#book1", "#book2", "#book3", "#book4", "#book5", "#book6", "#book7", "#book8", "#book9", "#book10"];
function splitName(plName,ballotNum) {
var halfplName = Math.round(plName.length / 2);
var firstplName = plName.substr(0, halfplName);
var lastplName = plName.substr(halfplName, plName.length);
$(ballotNum + ' ul.hardcover_front').find('li:nth-child(2)').html(firstplName);
$(ballotNum + ' ul.hardcover_back').find('li:nth-child(1)').html(lastplName);
}
for (i=0; i<ballots.length; i++) {
splitName(votenames[i],ballots[i]);
}
</script>