Suneesh
Suneesh

Reputation: 255

check div present in iframe body

I appended a div into iframe body like this

$('.editable iframe').contents().find('body').append('<div id="newe"></div>')

and it worked.

after that, I checked if that div is present in that by using $('#newe').length, but it gives null value, when inspected the div is present in the body.

editable is the class name of div (iframe is inside a div).

also tried document.getElementById('newe')

Upvotes: 2

Views: 284

Answers (1)

user13500
user13500

Reputation: 3856

$('#newe').length

Will search for elements with id in current document. To search the iframe you will need to use something like:

$('.editable iframe').contents().find('#newe')

You also need to use double quotes, or escape the single ones in:

.append('<div id='newe'></div>') // Bad

.append('<div id="newe"></div>') // OK

Simple fiddle

Upvotes: 3

Related Questions