あれこれ備忘録@はてなブログ

勉強したことやニュースや出来事を備忘録として書いていきます

このブログには広告が含まれます

jQuery難しいです

こういうものをjQueryで表現する時

image = document.createElement("img");

image.src = imageUrl;

image.alt = item.title;

image.width = 120;

image.height = 120;

$("img").attr({

src: imageUrl;

alt: item.title;

width: 120;

height: 120;

});

と書くんだと思うんですけど、これをさらに

a = document.createElement("a");

a.href = item.link;

a.target = "_blank";

a.appendChild(image);

みたいな感じで要素の中に加えていく時、これをjQueryで書くにはどうしたらいいんでしょうね。

上のa要素をjQuery形式で書いてappendしてもうまく行きません。

予めa要素を数だけHTMLに書いておいて、jQueryでそこに足すのが正しいやり方なんでしょうかね?