2014-02-15 127 views
-3
var contentofsel=$("#"+a).html().trim(); 
alert (contentofsel); 

$('#temstoredivid').append(
    "<div class="maincover" id="maincov1">" + 
    " <div class="subcover" id="subcover1"> </div>" + 
    " <div class="forclose" id="forcloseid1"> </div>" + 
    "</div>"); 

$('#temstoredivid .maincov1').html(contentofsel); 

我需要在div class subcover和id =「subcover1」中打印contentofsel的值。我嘗試了上面的代碼,但沒有工作。請幫我先生。如何將div添加到使用javascript的另一個div?

回答

2

你的字符串文字不能正確封閉

var contentofsel = $("#" + a).html().trim(); 
alert(contentofsel); 

var $el = $('<div class="maincover" id="maincov1">' + 
    ' <div class="subcover" id="subcover1 "></div>' + 
    ' <div class="forclose" id="forcloseid1"></div>' + 
    '</div>').appendTo('#temstoredivid'); 
//but since you are going to override the contents of .maincover element why are you adding 2 div's inside it in the above segment 

$el.html(contentofsel); 
相關問題