jquery - How can i set the text of a div dyanmically? -


i have static html

<div id="myordersdiv">              <ul>                     <li class="myorderhead"><h5>my orders <i>2</i></h5></li>                 </ul>             </div> 

here orders <i>2</i> represents number of orders present in

how can set text hardcoded 2 dynamically ??

var dataa = '<div id="ordersdiv" style="display:none"></div>';   $("#myordersdiv ul").append(dataa); $("#ordersdiv").prepend(buildcart);  $("#myordersdiv").show(); 

this html

<div id="myordersdiv">               <ul>                     <li class="myorderhead"><h5>my orders <i>2</i></h5></li>                  </ul>              </div> 

and calculating length way

 var dataa = '<div id="ordersdiv" style="display:none"></div>';   $("#myordersdiv ul").append(dataa);  $("#ordersdiv").prepend(buildcart); var n = $("#ordersdiv").length; $("#myordersdiv").find("i").text(n).show(); $("#myordersdiv").show(); 

but length being shown 1 .

you can this:

var somevariable = 2;  $("#myordersdiv").find("i").text(somevariable); 

demo fiddle


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -