开发者

Add html elements dynamically to a inner html of an li element

 function showHideMinMax(typeid ,value){
  // extract the index number from typeid
  var indexNr = typeid.match(/\d+/);
            if(value == "blah"){
                $("input#A"+indexNr).hide();
                $("input#B"+indexNr).hide();
                $("label[for=C"+indexNr+"]").hide();
                $("label[for=D"+indexNr+"]").hide();
            }else{
                $("input#A"+indexNr).show();
                $("input#B"+indexNr).show();
                $("label[for=C"+indexNr+"]").show();
                $("label[for=D"+indexNr+"]").show();
            }
     }

I have a javascript function like above. So what I want is that in the else part is that if the html elements mentioned above in the else part dosen't exits then create them and append to the html portion inside the li element. How can I achieve this.?

The li element looks like this and the above elements are inside this html li element

          <li 开发者_运维百科class="css" id="demo"+somenumber ">


You would use append or appendTo, e.g.:

var data = "<input type=\"text\" />";
$("#elementId").append(data);

Or:

$("<input type=\"text\" />").appendTo($("#elementId"));

Where elementId is the id of the li element. You'd need to adjust for your specific html.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜