no title...

Page 76

jQuery

Example Following is a simple example showing the usage of this method: <html> <head> <title>the title</title> <script type="text/javascript" src="/jquery/jquery-1.3.2.min.js"></script> <script type="text/javascript" language="javascript">

$(document).ready(function(){ var mappedItems = $("li").map(function (index) { var replacement = $("<li>").text($(this).text()).get(0); if (index == 0) { // make the first item all caps $(replacement).text($(replacement).text().toUpperCase()); } else if (index == 1 || index == 3) { // delete the second and fourth items replacement = null; } else if (index == 2) { // make two of the third item and add some text replacement = [replacement,$("<li>").get(0)]; $(replacement[0]).append("<b> - A</b>"); $(replacement[1]).append("Extra <b> - B</b>"); }

// replacement will be an dom element, null, // or an array of dom elements return replacement; }); $("#results").append(mappedItems);

}); </script> <style> body { font-size:16px; } ul { float:left; margin:0 30px; color:blue; } 67


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.