0

I have a fancynox with an iframe and html document with form in it.
I try to access the form's parent DOM element. The form's id is "form"
I tried:

$("#form").get(0).parentNode    
document.getElementsByTagName('iframe').getElementById('form')  //TypeError  
document.getElementsByTagName('iframe').document  //undefined  

How can I access the form?

lvil
  • 4,326
  • 9
  • 48
  • 76
  • Check this thread - [How to get iFrame src content using javascript?][1] [1]: http://stackoverflow.com/questions/1264569/how-to-get-iframe-src-content-using-javascript – George K Sep 03 '11 at 12:59
  • `$("#form")` accesses the form element, what specifically do you need to do ? – NimChimpsky Sep 03 '11 at 12:57
  • append a child node after the form. I think $("#form") is not a DOM node. – lvil Sep 03 '11 at 12:58

2 Answers2

1

$('#form') is the form in your case. It is the jQuery node, however, so you need to use jQuery functions on it...

Refer to the jQuery docs for more help on selectors and the available API jQuery Docs

Also, if you are using jQuery, you don't need to do all of the 'getElementById' stuff, as you can just access everything through jQuery selectors.

//A couple selector examples
$('#id')  //By Id
$('.class') //By Class
$('tag')  //By element tag
$('#id').next() //Get next element
$('#id').children() //list of child nodes
$('#id').find('#id2') //element id2 somewhere inside id1

For completeness, Here are some api examples

$('#id').css('background','red')  //Change background to red
$('#id').submit()  //if id element is a form, submit it
$('#id').val()  //if id element is an input, get its value
$('#id').text() //the text of an element
$('#id').hide() //hide the element
$('#id').show() //show the element
jyore
  • 4,715
  • 2
  • 21
  • 26
0

This should do what you want:

http://api.jquery.com/insertAfter/

Kev
  • 118,037
  • 53
  • 300
  • 385
Vyrx
  • 753
  • 1
  • 10
  • 15