私はいくつかのHTMLコンテンツを取得するためにjQueryでAJAXを使用しています。成功関数は次のとおりです。
function successFn(data) {
var keyWord = $("#input").val();
// convert string html to object
var anchors = $('<div/>').html(data).contents();
// add data-keyword to all results
anchors.each( function (i) {
$(this).attr('data-keyword', keyWord);
$(this).wrap('<div class="xXx"></div>');
});
// print results
$("#results").html(anchors);
}
にはdata
、アンカーのリストが含まれています。
<a href="link">...children...</a>
<a href="link">...children...</a>
<a href="link">...children...</a>
<a href="link">...children...</a>
したがって、これらのリンクに属性を追加しようとしていますが、これは機能しています。次に、各アンカーを div でラップしますが、機能していません。
なんでラッピングしないの?