Make jQuery on page add CSS class to div within iframe?
Can I have jQuery on my page that adds a CSS class to a div thats within an iframe?
Thanks
UPDATE. For testing purposes Ive added the following. I would have thought that it would add a class of 'red' to all p tags in any iframe, but its not doing anything:
$(document).ready(function() { $('iframe') .c开发者_开发知识库ontents() .find('p') .addClass('red'); });
Thanks
If it's on the same domain, you should be able to.
Try using something like this:
$('#iframe-id')
.contents()
.find('.my-div')
.addClass('my-other-class');
You can target a jquery selector on a specific element. In this case you will want to target the id / class of your div within the frames collection of your current page and perform the action.
See the following;
$('#mydivid', frames['myiframeid'].document).addClass('myclass');
精彩评论