Jquery – appending h2 to image with jquery

jquery

hi im trying to add a h2 with the title of an image after each image in my page… this is what ive got so far…

not really sure where im goin wrong

$("img[title]").each(function(){
   this.after("<h2>" . this.attr(title) "</h2>");
});

Best Answer

I think you're confusing JavaScript with php. Try:

$(this).after("<h2>" + $(this).attr('title') + "</h2>");