Web Development with jQuery®

(Elliott) #1

(^152) ❘ CHAPTER 5 ITERATION OF ARRAYS AND OBJECTS


  • Wait

  • If I Needed Someone

  • Run for Your Life






    The preceding markup document is styled with the following style sheet:
    body {
    font: 12px "Lucida Grande", Arial, sans-serif;
    color: rgb(50, 50, 50);
    margin: 0 ;
    padding: 0 10px;
    }
    ul {
    list-style: none;
    margin: 0 0 10px 0 ;
    padding: 10px;
    background: yellow;
    width: 350px;
    }
    ul li {
    padding: 3px;
    }
    h4 {
    margin: 10px 0 ;
    }
    ul#rubberSoulMapped {
    display: none;
    }
    The following script demonstrates how a selection is mapped to a new array:
    $(document).ready(
    function()
    {
    var mappedSongs = $('ul#rubberSoul li').map(
    function(key)
    {
    if ($(this).hasClass('John'))
    {
    return $(this).text() + ' John Lennon';
    }
    if ($(this).hasClass('Paul'))
    {
    return $(this).text() + ' Paul McCartney';
    }
    if ($(this).hasClass('George'))
    {
    return $(this).text() + ' George Harrison';
    }
    [http://www.it-ebooks.info](http://www.it-ebooks.info)
    Free download pdf