Search code examples
javascripthtmljqueryiframe

Is it possible to change only one <img> inside the content of iFrame?


I am using an iFrame to display an html file, that I don't have access to, The HTML file has a lot of image but I only want to change the first image in it. Is there any possible way to do this?

The code that I have is:

iFrame.contents().find("table").width(600);
iFrame.contents().find("img").width(500);

the iFrame.contents().find("img").width(500) changes all the <img> in the HTML.


Solution

  • Use the first method to reduce the list of matched elements to the first one.

    iFrame.contents().find("img").first().width(500);