开发者

jQuery access DOM element

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 for开发者_运维知识库m?


$('#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


This should do what you want:

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜