Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 1.66 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. In jquery-mobile how do you programmically add page elements that have all the css?
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5.         <meta name="viewport" content="width=device-width, initial-scale=1">
  6.         <link rel="stylesheet" href="http://code.jquery.com/mobile/latest/jquery.mobile.css" />
  7.         <script src="http://code.jquery.com/jquery.js"></script>
  8.         <script src="http://code.jquery.com/mobile/latest/jquery.mobile.js"></script>  
  9. </head>
  10. <body>
  11.     <div id="thelists" data-role="page">
  12.  
  13.         <div data-role="header">
  14.             <h1>My Title</h1>
  15.         </div><!-- /header -->      
  16.         <div data-role="content">  
  17.             <h3>Add List</h3>
  18.             <form>
  19.                 <div data-role="controlgroup"  id="addwhat">
  20.                     <input type="text" name="inp0" class="inp" />
  21.                 </div>  
  22.                 <div data-role="controlgroup" data-type="horizontal" class="aisubmit">
  23.                     <input type="submit" data-theme="b" id="addinput" value="Add Input"/>
  24.                 </div>                          
  25.              </form>
  26.         </div><!-- /content -->
  27.     </div><!-- /page -->
  28.     <script>
  29.     var ct =0;
  30.     $('body').on('click', "#addinput", function (e) {
  31.         ct++;
  32.         e.stopImmediatePropagation();
  33.         e.preventDefault();
  34.         //to add form elemnt you have to add all the class css stuff
  35.         //$('#addwhat').append('<input type="text" name="list' + ct + '" class="inp ui-input-text ui-body-c ui-corner-all ui-shadow-inset" />');
  36.         $('#addwhat').append('<input type="text" name="list' + ct + '"/>');
  37.     });              
  38.     </script>    
  39. </body>
  40. </html>
  41.        
  42. $('#thelists').trigger('create');