2016-08-22 1 views
3

セレクタ(この場合はセレクタ、セレクタ、#emp1-day3)にあるセレクタで見つかったjQueryオブジェクトを文字列(コンテンツ)に追加しようとしていますが、append関数は$(contents).find(selector)が正しいjQueryオブジェクトを返しても、jQueryオブジェクトが見つかりました。jQueryを使用してHTML文字列の中に見つかったセレクタにhtmlを追加するにはどうすればよいですか?

var nodeWorkShift = $('<div>' + stringWorkShift + '</div>'); 
$(contents).find(selector).append(nodeWorkShift); 

答えて

2

contentsの場合は、作成および変更のコレクションを捨てられるよう、あなたのコードが効果的に何もしない文字列です。コレクションを保存する必要があります。

var nodeWorkShift = $('<div>' + stringWorkShift + '</div>'); 
var $contents = $(contents).find(selector).append(nodeWorkShift).end(); 
// string representation of the collection 
console.log($contents.prop('outerHTML')); 
関連する問題