correct format jquery selectors?
The code below relates to a simplified form with a number of repetitive
sets of form fields. I'm writing some javascript to insert values in the
form fields and then display the form fields, but struggle to get the
right syntax for the jquery selectors - e.g., to use variables with the
selectors. I looked at http://api.jquery.com/html/ and
http://api.jquery.com/remove/ and some code examples like at
http://jsfiddle.net/LYDuZ/, but still get stuck. Pls your help with
respect to the right code for the javascript html() and remove() code.
Thank you in advance..
html code:
<style>
.hideElement {display:none;}
</style>
<form>
<!-- first set-->
<div id="product0" class="hideElement"> Product <br>
<p> productname: </p> <div id="fld_name0"> </div>
<!-- second set-->
<div id="product1" class="hideElement"> Product <br>
<p> productname: </p> <div id="fld_name1"> </div>
</form>
javascript code:
for(var i=0;i<msg.nrofproducts;i++){
$("#fld_name'+i'").html(msg.productname[i]);
$("#product'+i'").remove('.hideElement'); //finally show product
}//for i
No comments:
Post a Comment