开发者

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

开发者 https://www.devze.com 2023-03-21 23:30 出处:网络
function showHideMinMax(typeid ,value){ // extract the index number from typeid var indexNr = typeid.match(/\\d+/);
 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

精彩评论

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