User Interface Expert Question: Download UI Developer PDF

With jQuery, construct an array that has the values ["A", "B", "C", "D", "E", "F"] by getting the letters stored in the following html elements and pushing them into the array?

<div class="select-container" data-letter="A">
B
<div class="select-wrapper">
<ul>
<li id="select-first">D</li>
<li></li>
<li>E</li>
<li></li>
C
</ul>
</div>
<div>
<span>F</span>
</div>
</div>

Tweet Share WhatsApp

Answer:

var letterArray = [];
// A
letterArray.push($('.select-container').data("letter"));
// B
var b = $('.select-container').contents().filter(function() {
return this.nodeType === 3 && this.nodeValue.trim() !== '';
}).text().trim();
letterArray.push(b);
// C
var c = $('.select-wrapper ul').contents().filter(function() {
return this.nodeType === 3 && this.nodeValue.trim() !== '';
}).text().trim();
letterArray.push(c);
// D
letterArray.push($('#select-first').text());
//E
letterArray.push($('.select-wrapper li').eq(2).text());
// F
letterArray.push($('.select-container > div:last-child span').text());
// Console Log the array.
console.log(letterArray);

Download UI Developer PDF Read All 90 UI Developer Questions
Previous QuestionNext Question
How would we select the 3rd li element and retrieve the value of it's id attribute w/out selecting the li by id? *You can select it by index?

<ul id="list">
<li id="one"></li>
<li id="two"></li>
<li id="three"></li>
<li id="four"></li>
</ul>
Tell me what CSS class do you use to span 12 columns on medium sized screens but only 6 columns on large screens in the latest version of Bootstrap?