If you want to know if an element exists, you need to check the length property, see the jQuery FAQ :
if ($('#myFrame').length) { alert('#myFrame exists'); }
In your case, I think you want:
if ($('frame[name=header]', parent).length) { alert('frame exists'); }
Why check the length property?
Because if you pass a jQuery selector that does not match anything, the returned result is a jQuery object, it is not a false value (null, undefined, 0 or false) in the if statement condition evaluates to bool, and non 'falsy' always evaluates to true:
if ($('#nonExisting')) { alert('always true'); } // because !!$('#nonExisting') == true; // and !!'hello' == true; !!0 == false;
I used !! as an example of a simple way of turning any expression into its logical equivalent, which the if statement does behind the scenes ...
Edit: By looking at the layout of the frames and assuming that you want to check if the header frame exists from the main page, you can easily do this:
if (parent.header !== undefined) {
Or simply:
if (parent.header) {
Check out this example:
source share