You have an ordered list on your page. You select all the <li>elements of that list using jQuery; now you need to transform that list into another list.
Let’s say we have a list of people in an ordered list. We would like to display the first three people from that ordered list as a sentence:
Figure : shows the output.
We start by making an array of the <li>elements from the ordered list. We will select all <li>elements on the page by using a jQuery selector and pass that in as an argument of the jQuery utility method $.map(), which will take an existing array and “map” it in to another array. The second argument is the function that will iterate through the array, perform translations, and return a new value to be stored into a new array. In the preceding example, we iterate through the array we made, return only thehtml() values of the first three list elements, and map these values into a new array. We then take that array and use the join method to make a single string out of the array and inject it into the end of the document.
In the solution, we are using the jQuery utility method $.map(), which will transform an existing array into another array of items. $.map() takes two arguments, an array and a callback function:
$.map() will iterate through each item of the original array and pass in the item to be translated and the index of the current location within the array. The method is expecting a value to be returned. The returned value will be inserted into the new array.
J Query Related Interview Questions
|HTML 4 Interview Questions||HTML Interview Questions|
|HTML 5 Interview Questions||Zend Interview Questions|
|JqueryUI Interview Questions||Dynamic HTML Interview Questions|
|XQuery Interview Questions||jQuery Mobile Interview Questions|
J Query Related Practice Tests
|HTML 4 Practice Tests||HTML Practice Tests|
|HTML 5 Practice Tests||Zend Practice Tests|
|PHP and Jquery Practice Tests||J Query Practice Tests|
|CodeIgniter Practice Tests||Dynamic HTML Practice Tests|
J Query Tutorial
Selecting Elements With Jquery
Beyond The Basics
Faster, Simpler, More Fun
Html Form Enhancements From Scratch
Html Form Enhancements With Plugins
Interface Components From Scratch
User Interfaces With Jquery Ui
Jquery Ui Theming
Jquery, Ajax, Data Formats: Html, Xml, Json, Jsonp
Using Jquery In Large Projects
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.