Tony_Henrich
Tony_Henrich

Reputation: 44155

Searching for an image element whose src contains a keyword, in an iFrame's HTML using jQuery

I am digging deep into a page's DOM to manipulate a certain image attribute. I have a web page which contains an iFrame. The iFrame contains an image. The image has no id attribute so I am going to locate it using it's src. The src contains the unique keyword 'planet'. How do I locate this image using jQuery?

ADDITION:

I can't reference anything in the iFrame's DOM. Is there a special way to reference an element inside an iFrame?

Example: alert( $(myIframe).find('html').length ) reports 0, expecting 1.

Upvotes: 0

Views: 196

Answers (2)

Jeff Treuting
Jeff Treuting

Reputation: 13510

$(function() {
   var img = $('iframe img[src|=planet]');
});

Upvotes: 0

meder omuraliev
meder omuraliev

Reputation: 186662

I don't think you can manipulate iframe contents if the iframe's domain is not one you have control over.

EDIT: Since you said that it IS from the same domain now, $('#id').contents().find('a') should work.

Upvotes: 1

Related Questions