1

How can i use this to get the source of the image

function pinterest_it() {
    $("#page_wrapper img").after("<p>" + this.src + "</p>");
}

I'm guessing in this source code "this" is being used incorrectly. Can anyone tell me what i can use to get the images src?

4

2 回答 2

4

.after() accepts a function that should return an HTML string, DOM element or jQuery object to be appended after the elements in the selected set.

In that function, this is the current DOM element in the set, which in your case is the img.

$("#page_wrapper img").after(function(){
  return "<p>" + this.src + "</p>"
});
于 2013-10-18T11:27:28.053 回答
1

Try this:

$("#page_wrapper img").after(function(){
    return "<p>" + $(this).attr("src") + "</p>"
  });
于 2013-10-18T11:27:57.887 回答